Package com.sun.sgs.service

Examples of com.sun.sgs.service.DataService


    {
  if (name == null) {
      throw new NullPointerException("null name");
  }
  this.name = name;
  DataService dataService = getDataService();
  if (listener != null) {
      if (!(listener instanceof Serializable)) {
    throw new IllegalArgumentException("non-serializable listener");
      } else if (!(listener instanceof ManagedObject)) {
    listener = new ManagedSerializableChannelListener(listener);
      }
      this.listenerRef = dataService.createReference(listener);
  } else {
      this.listenerRef = null;
  }
  this.delivery = delivery;
  this.writeBufferCapacity = writeBufferCapacity;
  this.txn = ChannelServiceImpl.getTransaction();
  ManagedReference<ChannelImpl> ref = dataService.createReference(this);
  this.wrappedChannelRef =
      dataService.createReference(new ChannelWrapper(ref));
  this.channelRefId = ref.getId();
  this.coordNodeId = getLocalNodeId();
  if (logger.isLoggable(Level.FINER)) {
      logger.log(Level.FINER, "Created ChannelImpl:{0}",
           HexDumper.toHexString(channelRefId.toByteArray()));
  }
  getChannelsMap().put(name, this);
  EventQueue eventQueue = new EventQueue(this);
  eventQueueRef = dataService.createReference(eventQueue);
  getEventQueuesMap(coordNodeId).
      put(channelRefId.toString(), eventQueue);
    }
View Full Code Here


     *
     * 3} Finally, sends out a 'serviceEventQueue' request to the new
     * coordinator to restart this channel's event processing.
     */
    private void reassignCoordinator(long failedCoordNodeId) {
  DataService dataService = getDataService();
  dataService.markForUpdate(this);
  if (coordNodeId != failedCoordNodeId) {
      logger.log(
    Level.SEVERE,
    "attempt to reassign coordinator:{0} for channel:{1} " +
    "that is not the failed node:{2}",
View Full Code Here

     * created a wrapper for it), and the event queue and associated
     * binding from the data store.  This method should be called when
     * the channel is closed.
     */
    private void removeChannel() {
  DataService dataService = getDataService();
  removeAllSessions();
  getChannelsMap().removeOverride(name);
  dataService.removeObject(this);
  if (listenerRef != null) {
      ChannelListener maybeWrappedListener = listenerRef.get();
      if (maybeWrappedListener instanceof ManagedSerializable) {
    dataService.removeObject(maybeWrappedListener);
      }
  }
  BindingKeyedMap<EventQueue> eventQueuesMap =
      getEventQueuesMap(coordNodeId);
  eventQueuesMap.removeOverride(channelRefId.toString());
  EventQueue eventQueue = eventQueueRef.get();
  dataService.removeObject(eventQueue);
    }
View Full Code Here

  /**
   * Constructs an event queue for the specified {@code channel}.
   */
  EventQueue(ChannelImpl channel) {
      DataService dataService = getDataService();
      channelRef = dataService.createReference(channel);
      queueRef = dataService.createReference(
    new ManagedQueue<ChannelEvent>());
      writeBufferAvailable = channel.getWriteBufferCapacity();
  }
View Full Code Here

        channel.coordNodeId);
    return;
      }
      ChannelServiceImpl channelService =
    ChannelServiceImpl.getChannelService();
      DataService dataService = getDataService();
     
      /*
       * If a new coordinator has taken over (i.e., 'sendRefresh' is
       * true), then all pending events should to be serviced, since
       * a 'serviceEventQueue' request may have been missed when the
       * former channel coordinator failed and was in the process of
       * being reassigned.  So, assign the 'serviceAllEvents' flag
       * to indicate whether or not all pending events should be
       * processed below.
       */
      boolean serviceAllEvents = sendRefresh;
      if (sendRefresh) {
    final BigInteger channelRefId = getChannelRefId();
    final String channelName = channel.name;
    final Delivery channelDelivery = channel.delivery;
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(
      Level.FINEST, "sending refresh, channel:{0}",
      HexDumper.toHexString(channelRefId.toByteArray()));
    }
    for (final long nodeId : channel.servers) {
        channelService.addChannelTask(
          channelRefId,
      new IoRunnable() {
          public void run() throws IOException {
        ChannelServer server = getChannelServer(nodeId);
        if (server != null) {
            server.refresh(channelName, channelRefId,
               channelDelivery);
        }
          } },
      nodeId);
    }
    dataService.markForUpdate(this);
    sendRefresh = false;
      }

      /*
       * Process channel events.  If the 'serviceAllEvents' flag is
       * true, then service all pending events.
       */
      int eventsToService = channelService.eventsPerTxn;
      ManagedQueue<ChannelEvent> eventQueue = getQueue();
      do {
    ChannelEvent event = eventQueue.poll();
    if (event == null) {
        return;
    }

                logger.log(Level.FINEST, "processing event:{0}", event);
                int cost = event.getCost();
    if (cost > 0) {
        dataService.markForUpdate(this);
        writeBufferAvailable += cost;

        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST,
           "{0} cleared reservation of " +
View Full Code Here

  this.identity = identity;
  this.deliveries = deliveries;
  this.nodeId = sessionService.getLocalNodeId();
        this.maxMessageLength = maxMessageLength;
  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);
    }
View Full Code Here

     * Returns the event queue for the client session with the specified
     * {@code sessionId}, or null if the event queue is not bound in the
     * data service.
     */
    private static EventQueue getEventQueue(byte[] sessionId) {
  DataService dataService = ClientSessionServiceImpl.getDataService();
  String eventQueueKey = getEventQueueKey(sessionId);
  try {
      return (EventQueue) dataService.getServiceBinding(eventQueueKey);
  } catch (NameNotBoundException e) {
      return null;
  }
    }
View Full Code Here

  /**
   * Constructs an event queue for the specified {@code sessionImpl}.
   */
  EventQueue(ClientSessionImpl sessionImpl) {
      DataService dataService = ClientSessionServiceImpl.getDataService();
      sessionRef = dataService.createReference(sessionImpl);
      queueRef = dataService.createReference(
    new ManagedQueue<SessionEvent>());
      writeBufferAvailable = sessionImpl.writeBufferCapacity;
  }
View Full Code Here

      checkState();

      ClientSessionServiceImpl sessionService =
    ClientSessionServiceImpl.getInstance();
      ManagedQueue<SessionEvent> eventQueue = getQueue();
      DataService dataService =
    ClientSessionServiceImpl.getDataService();

      for (int i = 0; i < sessionService.eventsPerTxn; i++) {
    SessionEvent event = eventQueue.poll();
    if (event == null) {
        // no more events
        break;
    }

    logger.log(Level.FINEST, "processing event:{0}", event);

                int cost = event.getCost();
    if (cost > 0) {
        dataService.markForUpdate(this);
        writeBufferAvailable += cost;
        if (logger.isLoggable(Level.FINEST)) {
            logger.log(Level.FINEST,
           "{0} cleared reservation of " +
           "{1,number,#} bytes, leaving {2,number,#}",
View Full Code Here

  /* -- Implement ManagedObjectRemoval -- */

  /** {@inheritDoc} */
  public void removingObject() {
      try {
    DataService dataService =
        ClientSessionServiceImpl.getDataService();
    dataService.removeObject(queueRef.get());
      } catch (ObjectNotFoundException e) {
    // already removed.
      }
  }
View Full Code Here

TOP

Related Classes of com.sun.sgs.service.DataService

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.