use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext in project ecf by eclipse.
the class LocalAgent method subscribe.
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();
}
}
}
use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext in project ecf by eclipse.
the class DiscoveryAgent method deactivated.
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();
}
}
}
use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext in project ecf by eclipse.
the class DiscoveryAgent method activated.
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();
}
}
}
use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext in project ecf by eclipse.
the class DiscoveryAgent method connected.
protected void connected() {
if (isPrimary()) {
try {
config.getContext().sendCreate(null, new ReplicaSharedObjectDescription(getClass(), config.getSharedObjectID()));
} catch (IOException e) {
// 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();
}
}
}
use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext in project ecf by eclipse.
the class SubscriptionAgent method activated.
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());
}
}
Aggregations