Search in sources :

Example 1 with Replicated

use of org.teiid.Replicated in project teiid by teiid.

the class AbstractEventDistributorFactoryService method start.

public void start() {
    final EventDistributor ed = new EventDistributorImpl() {

        @Override
        public VDBRepository getVdbRepository() {
            return AbstractEventDistributorFactoryService.this.getVdbRepository();
        }

        @Override
        public DQPCore getDQPCore() {
            return AbstractEventDistributorFactoryService.this.getDQPCore();
        }
    };
    ObjectReplicator objectReplicator = getObjectReplicator();
    // this instance is by use of teiid internally; only invokes the remote instances
    if (objectReplicator != null) {
        try {
            // $NON-NLS-1$
            this.replicatableEventDistributor = objectReplicator.replicate("$TEIID_ED$", EventDistributor.class, ed, 0);
        } catch (Exception e) {
            LogManager.logError(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40088, this));
        }
    }
    // for external client to call. invokes local instance and remote ones too.
    this.eventDistributorProxy = (EventDistributor) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { EventDistributor.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            Replicated annotation = method.getAnnotation(Replicated.class);
            Object result = null;
            try {
                if (replicatableEventDistributor == null || (annotation != null && annotation.remoteOnly())) {
                    result = method.invoke(ed, args);
                }
                if (replicatableEventDistributor != null) {
                    result = method.invoke(replicatableEventDistributor, args);
                }
            } catch (InvocationTargetException e) {
                throw e.getTargetException();
            }
            return result;
        }
    });
}
Also used : EventDistributorImpl(org.teiid.deployers.EventDistributorImpl) Replicated(org.teiid.Replicated) EventDistributor(org.teiid.events.EventDistributor) ObjectReplicator(org.teiid.query.ObjectReplicator) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Replicated (org.teiid.Replicated)1 EventDistributorImpl (org.teiid.deployers.EventDistributorImpl)1 EventDistributor (org.teiid.events.EventDistributor)1 ObjectReplicator (org.teiid.query.ObjectReplicator)1