Package org.eclipse.ecf.core.sharedobject

Examples of org.eclipse.ecf.core.sharedobject.ISharedObjectContext


  protected boolean isPrimary() {
    return config.getContext().getLocalContainerID().equals(config.getHomeContainerID());
  }
 
  protected void activated() {
    ISharedObjectContext ctx = config.getContext();
    if (isPrimary()) {
      try {
        ctx.sendCreate(containerID, createReplicaDescription());
      } catch (IOException e) {
        callback.requestFailed(e);
        ctx.getSharedObjectManager().removeSharedObject(config.getSharedObjectID());
      }

      return;
    }
   
    ISharedObjectManager mgr = ctx.getSharedObjectManager();
    ISharedObject so = mgr.getSharedObject(sharedObjectID);
    try {
      ID homeContainerID = config.getHomeContainerID();
      if (so instanceof IPublishedService) {
        IPublishedService svc = (IPublishedService) so;
        svc.subscribe(homeContainerID, config.getSharedObjectID());
      } else {
        ctx.sendCreateResponse(homeContainerID, new IllegalArgumentException("Not an IPublishedService."), -1);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      ctx.getSharedObjectManager().removeSharedObject(config.getSharedObjectID());
    }
  }
View Full Code Here


     * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.identity.ID)
     */
    public synchronized void dispose(ID containerID) {
        if (config != null) {
            // TODO Do we even have a context now?
            ISharedObjectContext context = config.getContext();
            if (context != null
                    && context.getLocalContainerID().equals(containerID)) {
                config = null;
            }
        }
    }
View Full Code Here

     *
     * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID)
     */
    public synchronized void dispose(ID containerID) {
        if (config != null) {
          ISharedObjectContext context = config.getContext();
          if (context != null) {
            if (context.getLocalContainerID().equals(containerID)) {
              config = null;
            }
          }
        }
    }
View Full Code Here

      if (subscribers == null)
        return;
     
      subscribers.remove(requestorID);
      if (subscribers.isEmpty()) {
        ISharedObjectContext ctx = config.getContext();
        try {
          ctx.sendMessage(config.getHomeContainerID(), new UnsubscribeMessage());
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
       
        ctx.getSharedObjectManager().removeSharedObject(config.getSharedObjectID());
      }
    }
  }
View Full Code Here

  public void subscribe(ID containerID, ID requestorID) {
    synchronized (subscriptionMutex) {
      if (subscriptions == null)
        subscriptions = new HashSet();

      ISharedObjectContext ctx = config.getContext();
      try {
        if (subscriptions.add(containerID)) {
          ctx.sendCreate(containerID, createRemoteAgentDescription(requestorID));
        } else {
          SubscribeMessage msg = new SubscribeMessage(requestorID);
          ctx.sendMessage(containerID, SerializationUtil.serialize(msg));
        }
      } catch (IOException e) {
        // TODO Log me!
        e.printStackTrace();
      }
View Full Code Here

 
  protected void activated(ID sharedObjectID) {
    if (isPrimary())
      return;
   
    ISharedObjectContext ctx = config.getContext();
    Object object = ctx.getSharedObjectManager().getSharedObject(sharedObjectID);
    if (object instanceof IPublishedService) {
      IPublishedService svc = (IPublishedService) object;
      Map props = svc.getProperties();
      PublishedServiceDescriptor desc = new PublishedServiceDescriptor(ctx.getLocalContainerID(), sharedObjectID, props);
      try {
        ctx.sendMessage(config.getHomeContainerID(), SerializationUtil.serialize(new DiscoveryMessage(DiscoveryMessage.ADDED, desc)));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
View Full Code Here

 
  protected void deactivated(ID sharedObjectID) {
    if (isPrimary())
      return;

    ISharedObjectContext ctx = config.getContext();
    Object object = ctx.getSharedObjectManager().getSharedObject(sharedObjectID);
    if (object instanceof IPublishedService) {
      IPublishedService svc = (IPublishedService) object;
      Map props = svc.getProperties();
      PublishedServiceDescriptor desc = new PublishedServiceDescriptor(ctx.getLocalContainerID(), sharedObjectID, props);
      try {
        ctx.sendMessage(config.getHomeContainerID(), SerializationUtil.serialize(new DiscoveryMessage(DiscoveryMessage.REMOVED, desc)));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
View Full Code Here

        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    } else {
      ArrayList published = new ArrayList();
      ISharedObjectContext ctx = config.getContext();
      ISharedObjectManager mgr = ctx.getSharedObjectManager();
      ID[] ids = mgr.getSharedObjectIDs();
      ID containerID = ctx.getLocalContainerID();
      for (int i = 0; i < ids.length; ++i) {
        Object object = mgr.getSharedObject(ids[i]);
        if (object instanceof IPublishedService) {
          IPublishedService svc = (IPublishedService) object;
          Map props = svc.getProperties();
          published.add(new PublishedServiceDescriptor(containerID, ids[i], props));
        }
      }
     
      if (published.isEmpty())
        return;
     
      PublishedServiceDescriptor[] descriptors = new PublishedServiceDescriptor[published.size()];
      published.toArray(descriptors);
      try {
        ctx.sendMessage(config.getHomeContainerID(), SerializationUtil.serialize(new DiscoveryMessage(DiscoveryMessage.ADDED, descriptors)));
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.ecf.core.sharedobject.ISharedObjectContext

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.