diff options
Diffstat (limited to 'source/com/c2kernel/entity/proxy/EntityProxy.java')
| -rw-r--r-- | source/com/c2kernel/entity/proxy/EntityProxy.java | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/source/com/c2kernel/entity/proxy/EntityProxy.java b/source/com/c2kernel/entity/proxy/EntityProxy.java index b34653f..a9f6066 100644 --- a/source/com/c2kernel/entity/proxy/EntityProxy.java +++ b/source/com/c2kernel/entity/proxy/EntityProxy.java @@ -10,14 +10,17 @@ package com.c2kernel.entity.proxy;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.*;
-import com.c2kernel.persistency.*;
+import com.c2kernel.entity.C2KLocalObject;
+import com.c2kernel.entity.ManageableEntity;
+import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.property.Property;
-import com.c2kernel.utils.*;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
/******************************************************************************
@@ -35,7 +38,7 @@ abstract public class EntityProxy implements ManageableEntity protected ManageableEntity mEntity = null;
protected org.omg.CORBA.Object mIOR;
protected int mSystemKey;
- private HashMap<MemberSubscription, EntityProxyObserver> mSubscriptions;
+ private HashMap<MemberSubscription<?>, EntityProxyObserver<?>> mSubscriptions;
/**************************************************************************
*
@@ -45,7 +48,7 @@ abstract public class EntityProxy implements ManageableEntity throws ObjectNotFoundException
{
Logger.msg(8,"EntityProxy::EntityProxy() - Initialising '" +systemKey+ "' entity");
-
+
initialise( ior, systemKey);
}
@@ -60,7 +63,7 @@ abstract public class EntityProxy implements ManageableEntity mIOR = ior;
mSystemKey = systemKey;
- mSubscriptions = new HashMap<MemberSubscription, EntityProxyObserver>();
+ mSubscriptions = new HashMap<MemberSubscription<?>, EntityProxyObserver<?>>();
}
@@ -74,14 +77,15 @@ abstract public class EntityProxy implements ManageableEntity }
return mEntity;
}
-
+
abstract public ManageableEntity narrow() throws ObjectNotFoundException;
-
+
/**************************************************************************
*
**************************************************************************/
//check who is using.. and if toString() is sufficient
- public int getSystemKey()
+ @Override
+ public int getSystemKey()
{
return mSystemKey;
}
@@ -90,7 +94,8 @@ abstract public class EntityProxy implements ManageableEntity /**************************************************************************
*
**************************************************************************/
- public String queryData( String path )
+ @Override
+ public String queryData( String path )
throws ObjectNotFoundException
{
@@ -114,9 +119,9 @@ abstract public class EntityProxy implements ManageableEntity } catch (Exception e) {
Logger.error(e);
return "<ERROR>"+e.getMessage()+"</ERROR>";
- }
+ }
}
-
+
public String[] getContents( String path ) throws ObjectNotFoundException {
try {
return Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()));
@@ -160,39 +165,36 @@ abstract public class EntityProxy implements ManageableEntity throw new ObjectNotFoundException();
}
}
-
+
public String getName()
{
try {
- return getProperty("Name");
+ return getProperty("Name");
} catch (ObjectNotFoundException ex) {
return null;
}
}
-
+
/**************************************************************************
* Subscription methods
**************************************************************************/
- public void subscribe (EntityProxyObserver observer,
- String interest,
- boolean preload)
- {
- MemberSubscription newSub = new MemberSubscription(this, interest, observer, preload);
- synchronized (this){
- mSubscriptions.put( newSub, observer );
+ public void subscribe (MemberSubscription<?> newSub) {
+
+ newSub.setSubject(this);
+ synchronized (this){
+ mSubscriptions.put( newSub, newSub.getObserver() );
}
new Thread(newSub).start();
- Logger.msg(7, "Subscribed "+observer.getClass().getName()+" for "+interest);
+ Logger.msg(7, "Subscribed "+newSub.getObserver().getClass().getName()+" for "+newSub.interest);
}
-
- public void unsubscribe(EntityProxyObserver observer)
+ public void unsubscribe(EntityProxyObserver<?> observer)
{
synchronized (this){
- for (Iterator e = mSubscriptions.keySet().iterator(); e.hasNext();) {
- MemberSubscription thisSub = (MemberSubscription)e.next();
+ for (Iterator<MemberSubscription<?>> e = mSubscriptions.keySet().iterator(); e.hasNext();) {
+ MemberSubscription<?> thisSub = e.next();
if (mSubscriptions.get( thisSub ) == observer) {
e.remove();
Logger.msg(7, "Unsubscribed "+observer.getClass().getName());
@@ -200,14 +202,13 @@ abstract public class EntityProxy implements ManageableEntity }
}
}
-
+
public void dumpSubscriptions(int logLevel) {
if (mSubscriptions.size() == 0) return;
Logger.msg(logLevel, "Subscriptions to proxy "+mSystemKey+":");
synchronized(this) {
- for (Iterator iter = mSubscriptions.keySet().iterator(); iter.hasNext();) {
- MemberSubscription element = (MemberSubscription)iter.next();
- EntityProxyObserver obs = element.getObserver();
+ for (MemberSubscription<?> element : mSubscriptions.keySet()) {
+ EntityProxyObserver<?> obs = element.getObserver();
if (obs != null)
Logger.msg(logLevel, " "+element.getObserver().getClass().getName()+" subscribed to "+element.interest);
else
@@ -215,14 +216,14 @@ abstract public class EntityProxy implements ManageableEntity }
}
}
-
+
public void notify(ProxyMessage message) {
Logger.msg(4, "EntityProxy.notify() - Received change notification for "+message.getPath()+" on "+mSystemKey);
synchronized (this){
if (!message.getServer().equals(EntityProxyManager.serverName))
Gateway.getStorage().clearCache(mSystemKey, message.getPath());
- for (Iterator e = mSubscriptions.keySet().iterator(); e.hasNext();) {
- MemberSubscription newSub = (MemberSubscription)e.next();
+ for (Iterator<MemberSubscription<?>> e = mSubscriptions.keySet().iterator(); e.hasNext();) {
+ MemberSubscription<?> newSub = e.next();
if (newSub.getObserver() == null) { // phantom
Logger.msg(4, "Removing phantom subscription to "+newSub.interest);
e.remove();
@@ -232,11 +233,12 @@ abstract public class EntityProxy implements ManageableEntity }
}
}
-
+
/**
* If this is reaped, clear out the cache for it too.
*/
- protected void finalize() throws Throwable {
+ @Override
+ protected void finalize() throws Throwable {
Logger.msg(7, "Proxy "+mSystemKey+" reaped");
Gateway.getStorage().clearCache(mSystemKey, null);
Gateway.getProxyManager().removeProxy(mSystemKey);
|
