summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/proxy/EntityProxy.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/c2kernel/entity/proxy/EntityProxy.java')
-rw-r--r--src/main/java/com/c2kernel/entity/proxy/EntityProxy.java247
1 files changed, 0 insertions, 247 deletions
diff --git a/src/main/java/com/c2kernel/entity/proxy/EntityProxy.java b/src/main/java/com/c2kernel/entity/proxy/EntityProxy.java
deleted file mode 100644
index cb76a19..0000000
--- a/src/main/java/com/c2kernel/entity/proxy/EntityProxy.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/**************************************************************************
- * EntityProxy.java
- *
- * $Revision: 1.35 $
- * $Date: 2005/05/10 11:40:09 $
- *
- * Copyright (C) 2001 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-package com.c2kernel.entity.proxy;
-
-import java.util.HashMap;
-import java.util.Iterator;
-
-import com.c2kernel.common.ObjectNotFoundException;
-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.Logger;
-
-
-/******************************************************************************
-* It is a wrapper for the connection and communication with Entities.
-* It can cache data loaded from the Entity to reduce communication with it.
-* This cache is syncronised with corresponding Entity through an event mechanism.
-*
-* @version $Revision: 1.35 $ $Date: 2005/05/10 11:40:09 $
-* @author $Author: abranson $
-******************************************************************************/
-
-abstract public class EntityProxy implements ManageableEntity
-{
-
- protected ManageableEntity mEntity = null;
- protected org.omg.CORBA.Object mIOR;
- protected int mSystemKey;
- private HashMap<MemberSubscription<?>, EntityProxyObserver<?>> mSubscriptions;
-
- /**************************************************************************
- *
- **************************************************************************/
- protected EntityProxy( org.omg.CORBA.Object ior,
- int systemKey)
- throws ObjectNotFoundException
- {
- Logger.msg(8,"EntityProxy::EntityProxy() - Initialising '" +systemKey+ "' entity");
-
- initialise( ior, systemKey);
- }
-
- /**************************************************************************
- *
- **************************************************************************/
- private void initialise( org.omg.CORBA.Object ior,
- int systemKey)
- throws ObjectNotFoundException
- {
- Logger.msg(8, "EntityProxy::initialise() - Initialising '" +systemKey+ "' entity");
-
- mIOR = ior;
- mSystemKey = systemKey;
- mSubscriptions = new HashMap<MemberSubscription<?>, EntityProxyObserver<?>>();
- }
-
-
- /**************************************************************************
- *
- **************************************************************************/
- public ManageableEntity getEntity() throws ObjectNotFoundException
- {
- if (mEntity == null) {
- mEntity = narrow();
- }
- return mEntity;
- }
-
- abstract public ManageableEntity narrow() throws ObjectNotFoundException;
-
- /**************************************************************************
- *
- **************************************************************************/
- //check who is using.. and if toString() is sufficient
- @Override
- public int getSystemKey()
- {
- return mSystemKey;
- }
-
-
- /**************************************************************************
- *
- **************************************************************************/
- @Override
- public String queryData( String path )
- throws ObjectNotFoundException
- {
-
- try {
- Logger.msg(7, "EntityProxy.queryData() - "+mSystemKey+"/"+path);
- if (path.endsWith("all")) {
- Logger.msg(7, "EntityProxy.queryData() - listing contents");
- String[] result = Gateway.getStorage().getClusterContents(mSystemKey, path.substring(0, path.length()-3));
- StringBuffer retString = new StringBuffer();
- for (int i = 0; i < result.length; i++) {
- retString.append(result[i]);
- if (i<result.length-1) retString.append(",");
- }
- Logger.msg(7, "EntityProxy.queryData() - "+retString.toString());
- return retString.toString();
- }
- C2KLocalObject target = Gateway.getStorage().get(mSystemKey, path, null);
- return Gateway.getMarshaller().marshall(target);
- } catch (ObjectNotFoundException e) {
- throw e;
- } 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()));
- } catch (ClusterStorageException e) {
- throw new ObjectNotFoundException(e.toString());
- }
- }
-
-
- /**************************************************************************
- *
- **************************************************************************/
- public C2KLocalObject getObject( String xpath )
- throws ObjectNotFoundException
- {
- // load from storage, falling back to proxy loader if not found in others
- try
- {
- return Gateway.getStorage().get( mSystemKey, xpath , null);
- }
- catch( ClusterStorageException ex )
- {
- Logger.msg(4, "Exception loading object :"+mSystemKey+"/"+xpath);
- throw new ObjectNotFoundException( ex.toString() );
- }
- }
-
-
-
- public String getProperty( String name )
- throws ObjectNotFoundException
- {
- Logger.msg(5, "Get property "+name+" from syskey/"+mSystemKey);
- Property prop = (Property)getObject("Property/"+name);
- try
- {
- return prop.getValue();
- }
- catch (NullPointerException ex)
- {
- throw new ObjectNotFoundException();
- }
- }
-
- public String getName()
- {
- try {
- return getProperty("Name");
- } catch (ObjectNotFoundException ex) {
- return null;
- }
- }
-
-
- /**************************************************************************
- * Subscription methods
- **************************************************************************/
-
- public void subscribe (MemberSubscription<?> newSub) {
-
- newSub.setSubject(this);
- synchronized (this){
- mSubscriptions.put( newSub, newSub.getObserver() );
- }
- new Thread(newSub).start();
- Logger.msg(7, "Subscribed "+newSub.getObserver().getClass().getName()+" for "+newSub.interest);
- }
-
- public void unsubscribe(EntityProxyObserver<?> observer)
- {
- synchronized (this){
- 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());
- }
- }
- }
- }
-
- public void dumpSubscriptions(int logLevel) {
- if (mSubscriptions.size() == 0) return;
- Logger.msg(logLevel, "Subscriptions to proxy "+mSystemKey+":");
- synchronized(this) {
- for (MemberSubscription<?> element : mSubscriptions.keySet()) {
- EntityProxyObserver<?> obs = element.getObserver();
- if (obs != null)
- Logger.msg(logLevel, " "+element.getObserver().getClass().getName()+" subscribed to "+element.interest);
- else
- Logger.msg(logLevel, " Phantom subscription to "+element.interest);
- }
- }
- }
-
- 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<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();
- }
- else
- newSub.update(message.getPath(), message.getState());
- }
- }
- }
-
- /**
- * If this is reaped, clear out the cache for it too.
- */
- @Override
- protected void finalize() throws Throwable {
- Logger.msg(7, "Proxy "+mSystemKey+" reaped");
- Gateway.getStorage().clearCache(mSystemKey, null);
- Gateway.getProxyManager().removeProxy(mSystemKey);
- super.finalize();
- }
-
-}