use of org.jgroups.Channel in project wildfly by wildfly.
the class ProtocolResourceRegistrationHandler method findProtocol.
@Override
public Protocol findProtocol(OperationContext context) throws ClassNotFoundException, ModuleLoadException {
PathAddress address = context.getCurrentAddress();
String channelName = address.getParent().getLastElement().getValue();
String protocolName = address.getLastElement().getValue();
ServiceRegistry registry = context.getServiceRegistry(false);
ServiceController<?> controller = registry.getService(JGroupsRequirement.CHANNEL.getServiceName(context, channelName));
if (controller != null) {
Channel channel = (Channel) controller.getValue();
if (channel != null) {
controller = registry.getService(JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, channelName));
ChannelFactory factory = (ChannelFactory) controller.getValue();
if (factory != null) {
ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration();
ProtocolConfiguration<? extends TP> transport = configuration.getTransport();
if (transport.getName().equals(protocolName)) {
Class<? extends Protocol> protocolClass = transport.createProtocol().getClass();
return channel.getProtocolStack().findProtocol(protocolClass);
}
for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) {
if (protocol.getName().equals(protocolName)) {
Class<? extends Protocol> protocolClass = protocol.createProtocol().getClass();
return channel.getProtocolStack().findProtocol(protocolClass);
}
}
}
}
}
return null;
}
use of org.jgroups.Channel in project wildfly by wildfly.
the class ForkProtocolResourceRegistrationHandler method findProtocol.
@Override
public Protocol findProtocol(OperationContext context) throws ClassNotFoundException, ModuleLoadException {
PathAddress address = context.getCurrentAddress();
String channelName = address.getElement(address.size() - 3).getValue();
String forkName = address.getElement(address.size() - 2).getValue();
String protocolName = address.getElement(address.size() - 1).getValue();
ServiceRegistry registry = context.getServiceRegistry(false);
ServiceController<?> controller = registry.getService(JGroupsRequirement.CHANNEL.getServiceName(context, channelName));
if (controller != null) {
Channel channel = (Channel) controller.getValue();
if (channel != null) {
FORK fork = (FORK) channel.getProtocolStack().findProtocol(FORK.class);
if (fork != null) {
controller = registry.getService(JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, channelName));
if (controller != null) {
ChannelFactory factory = (ChannelFactory) controller.getValue();
if (factory != null) {
ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration();
ProtocolConfiguration<? extends TP> transport = configuration.getTransport();
if (transport.getName().equals(protocolName)) {
Class<? extends Protocol> protocolClass = transport.createProtocol().getClass();
return channel.getProtocolStack().findProtocol(protocolClass);
}
for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) {
if (protocol.getName().equals(protocolName)) {
Class<? extends Protocol> protocolClass = protocol.createProtocol().getClass();
return fork.get(forkName).getProtocolStack().findProtocol(protocolClass);
}
}
}
}
}
}
}
return null;
}
use of org.jgroups.Channel in project teiid by teiid.
the class JGroupsObjectReplicator method replicate.
@Override
public <T, S> T replicate(String mux_id, Class<T> iface, final S object, long startTimeout) throws Exception {
Channel channel = channelFactory.createChannel(mux_id);
// To keep the order of methods same at all the nodes.
TreeMap<String, Method> methods = new TreeMap<String, Method>();
for (Method method : iface.getMethods()) {
if (method.getAnnotation(Replicated.class) == null) {
continue;
}
methods.put(method.toGenericString(), method);
}
final HashMap<Method, Short> methodMap = new HashMap<Method, Short>();
final ArrayList<Method> methodList = new ArrayList<Method>();
for (String method : methods.keySet()) {
methodList.add(methods.get(method));
methodMap.put(methods.get(method), (short) (methodList.size() - 1));
}
Method hasState = ReplicatedObject.class.getMethod(HAS_STATE, new Class<?>[] { Serializable.class });
methodList.add(hasState);
methodMap.put(hasState, (short) (methodList.size() - 1));
Method sendState = JGroupsObjectReplicator.Streaming.class.getMethod(SEND_STATE, new Class<?>[] { Serializable.class, Address.class });
methodList.add(sendState);
methodMap.put(sendState, (short) (methodList.size() - 1));
// add in streaming methods
Method createState = JGroupsObjectReplicator.Streaming.class.getMethod(CREATE_STATE, new Class<?>[] { Serializable.class });
methodList.add(createState);
methodMap.put(createState, (short) (methodList.size() - 1));
Method buildState = JGroupsObjectReplicator.Streaming.class.getMethod(BUILD_STATE, new Class<?>[] { Serializable.class, byte[].class });
methodList.add(buildState);
methodMap.put(buildState, (short) (methodList.size() - 1));
Method finishState = JGroupsObjectReplicator.Streaming.class.getMethod(FINISH_STATE, new Class<?>[] { Serializable.class });
methodList.add(finishState);
methodMap.put(finishState, (short) (methodList.size() - 1));
ReplicatedInvocationHandler<S> proxy = new ReplicatedInvocationHandler<S>(object, methodMap);
/*
* TODO: could have an object implement streaming
* Override the normal handle method to support streaming
*/
ReplicatorRpcDispatcher disp = new ReplicatorRpcDispatcher<S>(channel, proxy, proxy, object, object, methodMap, methodList);
proxy.setDisp(disp);
disp.setMethodLookup(new MethodLookup() {
public Method findMethod(short id) {
return methodList.get(id);
}
});
T replicatedProxy = (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { iface }, proxy);
boolean success = false;
try {
channel.connect(mux_id);
if (object instanceof ReplicatedObject) {
((ReplicatedObject) object).setAddress(channel.getAddress());
proxy.pullState(null, null, null, startTimeout, startTimeout != 0 ? STATE_TIMEOUT : 0);
}
success = true;
return replicatedProxy;
} catch (Throwable e) {
if (e instanceof Exception) {
throw (Exception) e;
}
throw new TeiidRuntimeException(RuntimePlugin.Event.TEIID40104, e);
} finally {
if (!success) {
channel.close();
} else {
synchronized (disp) {
// mark as initialized so that state can be pulled if needed
disp.initialized = true;
}
}
}
}
use of org.jgroups.Channel in project teiid by teiid.
the class JGroupsObjectReplicatorService method start.
@Override
public void start(StartContext context) throws StartException {
this.replicator = new JGroupsObjectReplicator(new org.teiid.replication.jgroups.ChannelFactory() {
@Override
public Channel createChannel(String id) throws Exception {
Channel c = channelFactoryInjector.getValue().createChannel(id);
c.connect(id);
return c;
}
}, executorInjector.getValue());
}
use of org.jgroups.Channel in project teiid by teiid.
the class JGroupsObjectReplicator method stop.
public void stop(Object object) {
if (object == null || !Proxy.isProxyClass(object.getClass())) {
return;
}
ReplicatedInvocationHandler<?> handler = (ReplicatedInvocationHandler<?>) Proxy.getInvocationHandler(object);
Channel c = handler.disp.getChannel();
handler.disp.stop();
c.disconnect();
c.close();
}
Aggregations