/** {@inheritDoc} */
 @Override
 public String toString() {
   StringBuilder buf = new StringBuilder(getName());
   buf.append('@');
   if (getSession() == null) {
     buf.append("null");
   } else {
     buf.append(currentSessionRef.getId());
   }
   return buf.toString();
 }
Exemple #2
0
  /**
   * Sets the current <code>UserID</code> for this <code>Player</code>, which changes from session
   * to session. Typically this is called when the player first logs again, and not again until the
   * player logs out and logs back in.
   *
   * @param uid the player's user identifier
   */
  public void setCurrentSession(ClientSession session) {
    DataManager dataMgr = AppContext.getDataManager();
    dataMgr.markForUpdate(this);
    currentSessionRef = dataMgr.createReference(session);

    // Also inform the client of the session ID
    // FIXME, this is hacked in as the only non-channel message
    // for ease of porting -JM
    BigInteger sid = currentSessionRef.getId();
    byte[] bytes = sid.toByteArray();
    session.send(ByteBuffer.wrap(bytes));
  }
 /**
  * Constructs an instance of this class with the specified {@code sessionService}, {@code
  * identity}, and the local node ID, and stores this instance with the following bindings:
  *
  * <p>
  *
  * <pre>
  * com.sun.sgs.impl.service.session.impl.&lt;idBytes&gt;
  * com.sun.sgs.impl.service.session.node.&lt;nodeId&gt;.impl.&lt;idBytes&gt;
  * </pre>
  *
  * This method should only be called within a transaction.
  *
  * @param sessionService a client session service
  * @param identity the session's identity
  * @throws TransactionException if there is a problem with the current transaction
  */
 ClientSessionImpl(ClientSessionServiceImpl sessionService, Identity identity) {
   if (sessionService == null) {
     throw new NullPointerException("null sessionService");
   }
   if (identity == null) {
     throw new IllegalStateException("session's identity is not set");
   }
   this.sessionService = sessionService;
   this.identity = identity;
   this.nodeId = sessionService.getLocalNodeId();
   writeBufferCapacity = sessionService.getWriteBufferSize();
   DataService dataService = sessionService.getDataService();
   ManagedReference<ClientSessionImpl> sessionRef = dataService.createReference(this);
   id = sessionRef.getId();
   this.wrappedSessionRef = dataService.createReference(new ClientSessionWrapper(sessionRef));
   idBytes = id.toByteArray();
   dataService.setServiceBinding(getSessionKey(), this);
   dataService.setServiceBinding(getSessionNodeKey(), this);
   dataService.setServiceBinding(getEventQueueKey(), new EventQueue(this));
   logger.log(Level.FINEST, "Stored session, identity:{0} id:{1}", identity, id);
 }
 /** Returns the client session ID for this queue. */
 BigInteger getSessionRefId() {
   return sessionRef.getId();
 }