Package com.sun.sgs.app

Examples of com.sun.sgs.app.DataManager


      }
  }

  /** Removes some entries, returning true if there is more to do. */
  private boolean doWork() {
      DataManager dataManager = AppContext.getDataManager();
      dataManager.markForUpdate(this);
            ScalableHashMap<K, V> node = currentNodeRef.get();
      /* Find the leaf node */
      if (!node.isLeafNode()) {
    while (true) {
        currentNodeRef =
      uncheckedCast(node.nodeDirectory[offsets.peek()]);
        node = currentNodeRef.get();
        if (node.isLeafNode()) {
      break;
        }
        offsets.push(0);
    }
      }
      if (!node.removeSomeLeafEntries()) {
    /* More entries in this node */
    return true;
      }
      /* Search the parents for a non-empty node, removing empty ones */
      while (true) {
    currentNodeRef = node.parentRef;
    dataManager.removeObject(node);
    if (currentNodeRef == null) {
        break;
    }
    int offset = offsets.pop();
    node = currentNodeRef.get();
View Full Code Here


   * @param v the value
   */
  PrefixEntry(int h, K k, V v) {
      this.hash = h;

      DataManager dm = AppContext.getDataManager();

      // if both the key and value are not ManagedObjects, we can save a
      // get() and createReference() call each by merging them in a
      // single KeyValuePair
      if (!(k instanceof ManagedObject) &&
    !(v instanceof ManagedObject))
      {
    setKeyValuePair();
    keyOrPairRef = dm.createReference(
        new ManagedSerializable<Object>(
                        new KeyValuePair<K, V>(k, v)));
      } else {
    // For the key and value, if each is already a ManagedObject,
    // then we obtain a ManagedReference to the object itself,
    // otherwise, we need to wrap it in a ManagedSerializable and
    // get a ManagedReference to that
    setKeyWrapped(!(k instanceof ManagedObject));
    keyOrPairRef = dm.createReference(
        isKeyWrapped() ? new ManagedSerializable<Object>(k) : k);
    setValueWrapped(!(v instanceof ManagedObject));
    valueRef = dm.createReference(
        isValueWrapped() ? new ManagedSerializable<V>(v) : v);
      }
  }
View Full Code Here

   * value.
   *
   * @param newValue the value to be stored
   */
  void setValueInternal(V newValue) {
      DataManager dm = AppContext.getDataManager();
      if (newValue instanceof ManagedObject) {
    if (isKeyValuePair()) {
        /* Switch from wrapping key/value pair to wrapping key */
                    ManagedSerializable<KeyValuePair<K, V>> msPair =
      uncheckedCast(keyOrPairRef.get());
        ManagedSerializable<K> msKey =
      uncheckedCast(keyOrPairRef.get());
        msKey.set(msPair.get().getKey());
        setKeyWrapped(true);
    } else if (isValueWrapped()) {
        dm.removeObject(valueRef.get());
        setValueWrapped(false);
    }
    valueRef = dm.createReference(newValue);
      } else if (isKeyValuePair()) {
                ManagedSerializable<KeyValuePair<K, V>> msPair =
        uncheckedCast(keyOrPairRef.get());
    msPair.get().setValue(newValue);
      } else if (isKeyWrapped()) {
    /* Switch from wrapping key to wrapping key/value pair */
    ManagedSerializable<K> msKey =
        uncheckedCast(keyOrPairRef.get());
                ManagedSerializable<KeyValuePair<K, V>> msPair =
        uncheckedCast(keyOrPairRef.get());
                msPair.set(new KeyValuePair<K, V>(msKey.get(), newValue));
    if (isValueWrapped()) {
        dm.removeObject(valueRef.get());
    }
    setKeyValuePair();
      } else if (isValueWrapped()) {
    ManagedSerializable<V> ms = uncheckedCast(valueRef.get());
    ms.set(newValue);
      } else {
    valueRef = dm.createReference(
        new ManagedSerializable<V>(newValue));
    setValueWrapped(true);
      }
  }
View Full Code Here

   * ScalableHashMap#remove ScalableHashMap.remove}, or {@link #remove
   * remove} under the condition that this entry's map-managed object
   * will never be referenced again by the map.
   */
  final void unmanage() {
      DataManager dm = AppContext.getDataManager();

      if (isKeyValuePair()) {
    try {
        dm.removeObject(keyOrPairRef.get());
    } catch (ObjectNotFoundException onfe) {
        // silent
    }
      } else {
    if (isKeyWrapped()) {
        try {
      dm.removeObject(keyOrPairRef.get());
        } catch (ObjectNotFoundException onfe) {
      // silent
        }
    }
    if (isValueWrapped()) {
        try {
      dm.removeObject(valueRef.get());
        } catch (ObjectNotFoundException onfe) {
      // silent
        }
    }
      }
View Full Code Here

     * Get an instance of the PlacemarkRegistrySrv class
     * @return a shared instance of Darkstar web login
     */
    public static PlacemarkRegistrySrv getInstance() {
        PlacemarkRegistrySrv out;
        DataManager dm = AppContext.getDataManager();

        try {
            out = (PlacemarkRegistrySrv) dm.getBinding(BINDING_NAME);
        } catch (NameNotBoundException nnbe) {
            out = createInstance();
            dm.setBinding(BINDING_NAME, out);
        }

        return out;
    }
View Full Code Here

     *          January 1, 1970, or {@code TaskServiceImpl.START_NOW}
     * @param p the period between recurrences, or
     *          {@code TaskServiceImpl.PERIOD_NONE}
     */
    void resetValues(Task t, long s, long p) {
        DataManager dm = AppContext.getDataManager();
        dm.markForUpdate(this);

        /* If the Task is also a ManagedObject then the assumption is
           that the object was already managed by the application so we
           just keep a reference...otherwise, we make it part of our
           state, which has the effect of persisting the task. In either
           case we set one of the two fields to null to disambiguate
           what the situation is. */
        if (t instanceof ManagedObject) {
            taskRef = dm.createReference(t);
            task = null;
        } else {
            task = t;
            taskRef = null;
        }
View Full Code Here

        {
            this.type     = type;
            this.clientID = clientID;
       
            // create references
            DataManager dm = AppContext.getDataManager();
            channelRef     = dm.createReference(channel);
        }
View Full Code Here

        public ConnectionType getClientType() {
            return type;
        }

        public Set<WonderlandClientID> getClients() {
            DataManager dm = AppContext.getDataManager();
            Set<WonderlandClientID> out = new LinkedHashSet<WonderlandClientID>();

            for (Iterator<ClientSession> i = channelRef.get().getSessions();
                 i.hasNext();)
            {
                ManagedReference<ClientSession> ref = dm.createReference(i.next());
                out.add(new WonderlandClientID(ref));
            }
           
            return out;
        }
View Full Code Here

                // special case -- force ID of internal handler
                assignID = SessionInternalConnectionType.SESSION_INTERNAL_CLIENT_ID;
            }
           
            // create a ClientSessionSet and channel
            DataManager dm = AppContext.getDataManager();
            ChannelManager cm = AppContext.getChannelManager();
           
            ClientSessionSet sessions = new ClientSessionSet();
            String channelName = handler.getConnectionType().toString() +
                                 "(" + String.valueOf(assignID) + ")";
            Channel channel = cm.createChannel(channelName,
                                               null,
                                               Delivery.RELIABLE);

            // mark ourself for udate
            dm.markForUpdate(this);

            // add to the map
            HandlerRecord record = new HandlerRecord();
            record.ref = ref;
            record.channel  = dm.createReference(channel);
            record.sessions = dm.createReference(sessions);
            record.clientID = assignID;
            handlers.put(handler.getConnectionType(), record);
           
            return record.clientID;
        }
View Full Code Here

         * Unregister a handler
         * @param handler the handler to unregister
         */
        public void unregister(ClientConnectionHandler handler) {
            // mark ourself for udate
            DataManager dm = AppContext.getDataManager();
            dm.markForUpdate(this);

            HandlerRecord record = handlers.remove(handler.getConnectionType());
 
            // remove the channel and session store
            dm.removeObject(record.channel.get());
            dm.removeObject(record.sessions.get());
           
            // clear the reference, which will remove a managed object
            // handler from the data store
            if (record != null) {
                record.ref.clear();
View Full Code Here

TOP

Related Classes of com.sun.sgs.app.DataManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.