Package com.sun.sgs.app

Examples of com.sun.sgs.app.DataManager


   * @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());
                dm.markForUpdate(msPair);
    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());
                dm.markForUpdate(msPair);
                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

        // NOTE: we can't directly save the item in the list, or
        // we'll end up with a local copy of the item. Instead, we
        // must save a ManagedReference to the item.

        DataManager dataManager = AppContext.getDataManager();
        dataManager.markForUpdate(this);

        return items.add(dataManager.createReference(item));
    }
View Full Code Here

     */
    public boolean addPlayer(SwordWorldPlayer player) {
        logger.log(Level.INFO, "{0} enters {1}",
            new Object[] { player, this });

        DataManager dataManager = AppContext.getDataManager();
        dataManager.markForUpdate(this);

        return players.add(dataManager.createReference(player));
    }
View Full Code Here

     */
    public boolean removePlayer(SwordWorldPlayer player) {
        logger.log(Level.INFO, "{0} leaves {1}",
            new Object[] { player, this });

        DataManager dataManager = AppContext.getDataManager();
        dataManager.markForUpdate(this);

        return players.remove(dataManager.createReference(player));
    }
View Full Code Here

     */
    public static SwordWorldPlayer loggedIn(ClientSession session) {
        String playerBinding = PLAYER_BIND_PREFIX + session.getName();

        // try to find player object, if non existent then create
        DataManager dataMgr = AppContext.getDataManager();
        SwordWorldPlayer player;

        try {
            player = (SwordWorldPlayer) dataMgr.getBinding(playerBinding);
        } catch (NameNotBoundException ex) {
            // this is a new player
            player = new SwordWorldPlayer(playerBinding);
            logger.log(Level.INFO, "New player created: {0}", player);
            dataMgr.setBinding(playerBinding, player);
        }
        player.setSession(session);
        return player;
    }
View Full Code Here

     * Mark this player as logged in on the given session.
     *
     * @param session the session this player is logged in on
     */
    protected void setSession(ClientSession session) {
        DataManager dataMgr = AppContext.getDataManager();
        dataMgr.markForUpdate(this);

        currentSessionRef = dataMgr.createReference(session);

        logger.log(Level.INFO,
            "Set session for {0} to {1}",
            new Object[] { this, session });
    }
View Full Code Here

     * is null, marks the player as not in any room.
     * <p>
     * @param room the room this player should be in, or {@code null}
     */
    protected void setRoom(SwordWorldRoom room) {
        DataManager dataManager = AppContext.getDataManager();
        dataManager.markForUpdate(this);

        if (room == null) {
            currentRoomRef = null;
            return;
        }

        currentRoomRef = dataManager.createReference(room);
    }
View Full Code Here

    {
        if (session == null) {
            throw new NullPointerException("null session");
        }

        DataManager dataMgr = AppContext.getDataManager();
        sessionRef = dataMgr.createReference(session);
        sessionName = session.getName();
       
        // Join the session to all channels.  We obtain the channel
        // in two different ways, by reference and by name.
        ChannelManager channelMgr = AppContext.getChannelManager();
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.