ClusteredRemotingpublic class ClusteredRemoting extends Object implements ClusterConstants
Fields Summary |
---|
private static final Logger | log |
Methods Summary |
---|
public static org.jboss.aop.proxy.ClassProxy | clusterObject(java.lang.Object objectId, java.lang.Object obj, java.lang.String partitionName, org.jboss.ha.framework.interfaces.LoadBalancePolicy lb, org.jboss.remoting.InvokerLocator locator)
String proxyFamilyName = objectId.toString() + locator.getProtocol() + partitionName;
HAPartition partition = (HAPartition) new InitialContext().lookup("/HAPartition/" + partitionName);
HATarget target = null;
Map families = null;
InstanceAdvisor advisor = null;
Class clazz;
if (obj instanceof Advised)
{
advisor = ((Advised) obj)._getInstanceAdvisor();
clazz = obj.getClass();
Dispatcher.singleton.registerTarget(objectId, obj);
}
else
{
clazz = obj.getClass();
ClassProxy proxy = ClassProxyFactory.newInstance(obj.getClass());
advisor = proxy._getInstanceAdvisor();
advisor.insertInterceptor(new ForwardingInterceptor(obj));
Dispatcher.singleton.registerTarget(objectId, proxy);
}
families = (Map) advisor.getMetaData().getMetaData(CLUSTERED_REMOTING, CLUSTER_FAMILIES);
if (families != null)
{
target = (HATarget) families.get(proxyFamilyName);
if (target == null)
{
target = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
ClusteringTargetsRepository.initTarget(proxyFamilyName, target.getReplicants());
families.put(proxyFamilyName, target);
}
}
else
{
families = new HashMap();
target = new HATarget(partition, proxyFamilyName, locator, HATarget.ENABLE_INVOCATIONS);
ClusteringTargetsRepository.initTarget(proxyFamilyName, target.getReplicants());
families.put(proxyFamilyName, target);
advisor.insertInterceptor(0, new ReplicantsManagerInterceptor(families));
}
ClassProxy proxy = ClassProxyFactory.newInstance(clazz);
InstanceAdvisor proxyAdvisor = proxy._getInstanceAdvisor();
proxyAdvisor.insertInterceptor(IsLocalInterceptor.singleton);
advisor.insertInterceptor(SecurityClientInterceptor.singleton);
advisor.insertInterceptor(ClientTxPropagationInterceptor.singleton);
proxyAdvisor.insertInterceptor(MergeMetaDataInterceptor.singleton);
proxyAdvisor.insertInterceptor(ClusterChooserInterceptor.singleton);
proxyAdvisor.insertInterceptor(InvokeRemoteInterceptor.singleton);
proxyAdvisor.getMetaData().addMetaData(CLUSTERED_REMOTING,
CLUSTER_FAMILY_WRAPPER,
new FamilyWrapper(proxyFamilyName, target.getReplicants()),
PayloadKey.AS_IS);
// LB policy should be AS_IS so that remoting framework downloads the classes
proxyAdvisor.getMetaData().addMetaData(CLUSTERED_REMOTING,
LOADBALANCE_POLICY,
lb,
PayloadKey.AS_IS);
proxyAdvisor.getMetaData().addMetaData(InvokeRemoteInterceptor.REMOTING,
InvokeRemoteInterceptor.SUBSYSTEM,
"AOP",
PayloadKey.AS_IS);
proxyAdvisor.getMetaData().addMetaData(Dispatcher.DISPATCHER,
Dispatcher.OID,
objectId,
PayloadKey.AS_IS);
return proxy;
| public static void | unregisterClusteredObject(java.lang.Object object)
try
{
ClassProxy proxy = (ClassProxy) object;
InstanceAdvisor advisor = proxy._getInstanceAdvisor();
String oid = (String) advisor.getMetaData().getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
InstanceAdvised registeredObject = (InstanceAdvised) Dispatcher.singleton.getRegistered(oid);
if (registeredObject == null) throw new NotRegisteredException(oid.toString() + " is not registered");
Dispatcher.singleton.unregisterTarget(oid);
advisor = registeredObject._getInstanceAdvisor();
Map families = (Map) advisor.getMetaData().getMetaData(CLUSTERED_REMOTING, CLUSTER_FAMILIES);
Iterator it = families.values().iterator();
while (it.hasNext())
{
HATarget target = (HATarget) it.next();
target.destroy();
}
}
catch (Exception ignored)
{
log.trace("Ignored exception unregistering a clustered object", ignored);
}
|
|