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);
  if (channelWrapper == null) {
      channelWrapper = new ChannelWrapper(ref);
  } else {
      channelWrapper.setChannelRef(ref);
  }
  this.wrappedChannelRef = dataService.createReference(channelWrapper);
  this.channelRefId = ref.getId();
  this.coordNodeId = getLocalNodeId();
  if (logger.isLoggable(Level.FINER)) {
      logger.log(Level.FINER, "Created ChannelImpl:{0}", channelRefId);
  }
  getChannelsMap().putOverride(name, this);
  EventQueue eventQueue = new EventQueue(this);
  eventQueueRef = dataService.createReference(eventQueue);
  getEventQueuesMap(coordNodeId).
      put(channelRefId.toString(), eventQueue);
    }
View Full Code Here


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

  /*
   * Assign a new coordinator, and store event queue in new
   * coordinator's event queue map.
   */
  dataService.markForUpdate(this);
  coordNodeId = chooseCoordinatorNode();
  isCoordinatorReassigned = true;
  if (logger.isLoggable(Level.FINER)) {
      logger.log(
    Level.FINER,
View Full Code Here

     * which case the channel's name binding is not removed) and is
     * called when the channel is closed (in which case the channel's
     * name binding is removed).
     */
    private void removeChannel(boolean removeName) {
  DataService dataService = getDataService();
  if (removeName) {
      getChannelsMap().removeOverride(name);
  }
  dataService.removeObject(this);
  if (listenerRef != null) {
      ChannelListener maybeWrappedListener = null;
      try {
    maybeWrappedListener = listenerRef.get();
      } catch (ObjectNotFoundException ignore) {
    // listener already removed
      }
      if (maybeWrappedListener instanceof ManagedSerializable) {
    dataService.removeObject(maybeWrappedListener);
      }
  }
  BindingKeyedMap<EventQueue> eventQueuesMap =
      getEventQueuesMap(coordNodeId);
  eventQueuesMap.removeOverride(channelRefId.toString());
  EventQueue eventQueue = eventQueueRef.get();
  dataService.removeObject(eventQueue);
  if (isReliable()) {
      SavedMessageReaper.scheduleNewTask(channelRefId, true);
  }
    }
View Full Code Here

      if (savedMessages.isEmpty()) {
    // Saved messages no longer exist, so "cancel" periodic task.
    return;
      } else {
    // Remove messages saved past their expiration time.
    DataService dataService = getDataService();
    TaskManager taskManager = AppContext.getTaskManager();
    Iterator<ChannelMessageInfo> iter =
        savedMessages.values().iterator();
    while (taskManager.shouldContinue() && iter.hasNext()) {
        ChannelMessageInfo messageInfo = iter.next();
        if (messageInfo.isExpired()) {
      if (logger.isLoggable(Level.FINEST)) {
          logger.log(
        Level.FINEST,
        "Removing saved message, channel:{0} " +
        "timestamp:{1}", channelRefId,
        messageInfo.timestamp);
      }
      iter.remove();
      dataService.removeObject(messageInfo);
        } else {
      break;
        }
    }
    if (!savedMessages.isEmpty()) {
View Full Code Here

     * within a transaction.
     */
    private static Map<Long, Set<ProtocolDescriptor>>
  getProtocolDescriptorsMap()
    {
  DataService dataService = getInstance().getDataService();
  Map<Long, Set<ProtocolDescriptor>> protocolDescriptorsMap;
  try {
      protocolDescriptorsMap = Objects.uncheckedCast(
    dataService.getServiceBinding(PROTOCOL_DESCRIPTORS_MAP_KEY));
  } catch (NameNotBoundException e) {
      protocolDescriptorsMap =
    new ScalableHashMap<Long, Set<ProtocolDescriptor>>();
      dataService.setServiceBinding(PROTOCOL_DESCRIPTORS_MAP_KEY,
            protocolDescriptorsMap);
  }
  return protocolDescriptorsMap;
    }
View Full Code Here

   * also removes the protocol descriptors for the node
   * specified during construction.
   */
  public void run() {
      String sessionServerKey = getClientSessionServerKey(nodeId);
      DataService dataService = getInstance().getDataService();
      try {
    dataService.removeObject(
        dataService.getServiceBinding(sessionServerKey));
    getProtocolDescriptorsMap().remove(nodeId);
      } catch (NameNotBoundException e) {
    // already removed
    return;
      } catch (ObjectNotFoundException e) {
      }
      dataService.removeServiceBinding(sessionServerKey);
  }
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

            this.properties = properties;
        }

        /** Starts the application, throwing an exception on failure. */
        public void run() throws Exception {
            DataService dataService =
                Kernel.proxy.getService(DataService.class);
            try {
                // test to see if this name if the listener is already bound...
                dataService.getServiceBinding(StandardProperties.APP_LISTENER);
            } catch (NameNotBoundException nnbe) {
                // ...if it's not, create and then bind the listener
                AppListener listener =
                    (new PropertiesWrapper(properties)).
                    getClassInstanceProperty(StandardProperties.APP_LISTENER,
                                             AppListener.class, new Class[] {});
                if (listener instanceof ManagedObject) {
                    dataService.setServiceBinding(
                            StandardProperties.APP_LISTENER, listener);
                } else {
                    dataService.setServiceBinding(
                            StandardProperties.APP_LISTENER,
                            new ManagedSerializable<AppListener>(listener));
                }

                // since we created the listener, we're the first one to
View Full Code Here

    {
  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);
  if (channelWrapper == null) {
      channelWrapper = new ChannelWrapper(ref);
  } else {
      channelWrapper.setChannelRef(ref);
  }
  this.wrappedChannelRef = dataService.createReference(channelWrapper);
  this.channelRefId = ref.getId();
  this.coordNodeId = getLocalNodeId();
  if (logger.isLoggable(Level.FINER)) {
      logger.log(Level.FINER, "Created ChannelImpl:{0}",
           HexDumper.toHexString(channelRefId));
  }
  getChannelsMap().putOverride(name, this);
  EventQueue eventQueue = new EventQueue(this);
  eventQueueRef = dataService.createReference(eventQueue);
  getEventQueuesMap(coordNodeId).
      put(channelRefId.toString(), eventQueue);
    }
View Full Code Here

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

  /*
   * Assign a new coordinator, and store event queue in new
   * coordinator's event queue map.
   */
  dataService.markForUpdate(this);
  coordNodeId = chooseCoordinatorNode();
  isCoordinatorReassigned = true;
  if (logger.isLoggable(Level.FINER)) {
      logger.log(
    Level.FINER,
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.