// Path: core/src/main/java/com/threerings/nexus/distrib/DistribUtil.java
// public class DistribUtil
// {
//     public static void init (NexusObject object, int id, EventSink sink) {
//         object.init(id, sink);
//     }
// 
//     public static void clear (NexusObject object) {
//         object.clear();
//     }
// 
//     public static <R> void dispatchCall (NexusObject object, int attrIdx, short methId,
//                                          Object[] args, Slot<? super Try<R>> slot) {
//         DService.Dispatcher<?> disp = null;
//         try {
//             @SuppressWarnings("unchecked") RFuture<R> result = (RFuture<R>)
//                 object.<DService.Dispatcher<?>>getAttribute(attrIdx).dispatchCall(methId, args);
//             if (result != null) result.onComplete(slot);
// 
//         } catch (NexusException ne) {
//             if (slot != null) slot.onEmit(Try.<R>failure(ne));
//             else log.warning("Service call failed", "obj", object, "attr", disp,
//                              "methId", methId, ne);
// 
//         } catch (Throwable t) {
//             log.warning("Service call failed", "obj", object, "attr", disp, "methId", methId, t);
//             if (slot != null) slot.onEmit(Try.<R>failure(new NexusException("Internal error")));
//         }
//     }
// 
//     /**
//      * Returns a sentinel value for use by events in tracking unset values.
//      */
//     public static <T> T sentinelValue () {
//         @SuppressWarnings("unchecked") T value = (T)SENTINEL_VALUE;
//         return value;
//     }
// 
//     private DistribUtil () {} // no constructsky
// 
//     /** Used by {@link #sentinelValue}. */
//     private static final Object SENTINEL_VALUE = new Object();
// }


import com.threerings.nexus.distrib.DistribUtil;
import com.google.common.collect.Maps;
//
// Nexus Server - server-side support for Nexus distributed application framework
// http://github.com/threerings/nexus/blob/master/LICENSE

package com.threerings.nexus.server;



/**
 * A map whose contents are mirrored across all servers in the network.
 */
class GlobalMap<K,V> extends react.RMap<K,V>
{
    public GlobalMap (String id, ObjectManager omgr) {
        super(Maps.<K,V>newConcurrentMap());
        _id = id;
        _omgr = omgr;
    }

    public void applyPut (K key, V value, V oldValue) {
        if (oldValue == DistribUtil.<V>sentinelValue()) {
            // we came in over the network: update our underlying map
// Path: core/src/main/java/com/threerings/nexus/distrib/DistribUtil.java
// public class DistribUtil
// {
//     public static void init (NexusObject object, int id, EventSink sink) {
//         object.init(id, sink);
//     }
// 
//     public static void clear (NexusObject object) {
//         object.clear();
//     }
// 
//     public static <R> void dispatchCall (NexusObject object, int attrIdx, short methId,
//                                          Object[] args, Slot<? super Try<R>> slot) {
//         DService.Dispatcher<?> disp = null;
//         try {
//             @SuppressWarnings("unchecked") RFuture<R> result = (RFuture<R>)
//                 object.<DService.Dispatcher<?>>getAttribute(attrIdx).dispatchCall(methId, args);
//             if (result != null) result.onComplete(slot);
// 
//         } catch (NexusException ne) {
//             if (slot != null) slot.onEmit(Try.<R>failure(ne));
//             else log.warning("Service call failed", "obj", object, "attr", disp,
//                              "methId", methId, ne);
// 
//         } catch (Throwable t) {
//             log.warning("Service call failed", "obj", object, "attr", disp, "methId", methId, t);
//             if (slot != null) slot.onEmit(Try.<R>failure(new NexusException("Internal error")));
//         }
//     }
// 
//     /**
//      * Returns a sentinel value for use by events in tracking unset values.
//      */
//     public static <T> T sentinelValue () {
//         @SuppressWarnings("unchecked") T value = (T)SENTINEL_VALUE;
//         return value;
//     }
// 
//     private DistribUtil () {} // no constructsky
// 
//     /** Used by {@link #sentinelValue}. */
//     private static final Object SENTINEL_VALUE = new Object();
// }


// Path: server/src/main/java/com/threerings/nexus/server/GlobalMap.java
import com.threerings.nexus.distrib.DistribUtil;
import com.google.common.collect.Maps;

//
// Nexus Server - server-side support for Nexus distributed application framework
// http://github.com/threerings/nexus/blob/master/LICENSE

package com.threerings.nexus.server;



/**
 * A map whose contents are mirrored across all servers in the network.
 */
class GlobalMap<K,V> extends react.RMap<K,V>
{
    public GlobalMap (String id, ObjectManager omgr) {
        super(Maps.<K,V>newConcurrentMap());
        _id = id;
        _omgr = omgr;
    }

    public void applyPut (K key, V value, V oldValue) {
        if (oldValue == DistribUtil.<V>sentinelValue()) {
            // we came in over the network: update our underlying map
            oldValue = _impl.put(key, value);