Search in sources :

Example 1 with Channel

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;
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Channel(org.jgroups.Channel) ProtocolStackConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Example 2 with Channel

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;
}
Also used : FORK(org.jgroups.protocols.FORK) PathAddress(org.jboss.as.controller.PathAddress) Channel(org.jgroups.Channel) ProtocolStackConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Example 3 with Channel

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;
            }
        }
    }
}
Also used : Replicated(org.teiid.Replicated) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) MethodLookup(org.jgroups.blocks.MethodLookup) Channel(org.jgroups.Channel) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ReplicatedObject(org.teiid.query.ReplicatedObject)

Example 4 with Channel

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());
}
Also used : JGroupsObjectReplicator(org.teiid.replication.jgroups.JGroupsObjectReplicator) Channel(org.jgroups.Channel) ChannelFactory(org.wildfly.clustering.jgroups.ChannelFactory)

Example 5 with Channel

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();
}
Also used : Channel(org.jgroups.Channel)

Aggregations

Channel (org.jgroups.Channel)5 PathAddress (org.jboss.as.controller.PathAddress)2 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)2 ChannelFactory (org.wildfly.clustering.jgroups.spi.ChannelFactory)2 ProtocolStackConfiguration (org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MethodLookup (org.jgroups.blocks.MethodLookup)1 FORK (org.jgroups.protocols.FORK)1 Replicated (org.teiid.Replicated)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 ReplicatedObject (org.teiid.query.ReplicatedObject)1 JGroupsObjectReplicator (org.teiid.replication.jgroups.JGroupsObjectReplicator)1 ChannelFactory (org.wildfly.clustering.jgroups.ChannelFactory)1