Search in sources :

Example 1 with ObjectReplicator

use of org.teiid.query.ObjectReplicator 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)

Example 2 with ObjectReplicator

use of org.teiid.query.ObjectReplicator in project teiid by teiid.

the class AbstractEventDistributorFactoryService method stop.

public void stop() {
    ObjectReplicator objectReplicator = getObjectReplicator();
    if (objectReplicator != null && this.replicatableEventDistributor != null) {
        objectReplicator.stop(this.replicatableEventDistributor);
        this.replicatableEventDistributor = null;
    }
}
Also used : ObjectReplicator(org.teiid.query.ObjectReplicator)

Example 3 with ObjectReplicator

use of org.teiid.query.ObjectReplicator in project teiid by teiid.

the class TestReplication method testLargeReplicationFailedTransfer.

@Test
public void testLargeReplicationFailedTransfer() throws Exception {
    server1 = createServer("infinispan-replicated-config.xml", "tcp-shared.xml");
    deployLargeVDB(server1);
    Connection c1 = server1.createConnection("jdbc:teiid:large");
    Statement stmt = c1.createStatement();
    stmt.execute("select * from c");
    ResultSet rs = stmt.getResultSet();
    int rowCount = 0;
    while (rs.next()) {
        rowCount++;
    }
    Thread.sleep(1000);
    server2 = createServer("infinispan-replicated-config-1.xml", "tcp-shared.xml");
    // add a replicator to kill transfers
    final ObjectReplicator or = server2.getObjectReplicator();
    server2.setObjectReplicator(new ObjectReplicator() {

        @Override
        public void stop(Object o) {
        }

        @Override
        public <T, S> T replicate(String id, Class<T> iface, final S object, long startTimeout) throws Exception {
            Object o = Proxy.newProxyInstance(TestReplication.class.getClassLoader(), new Class<?>[] { iface, ReplicatedObject.class }, new InvocationHandler() {

                @Override
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    if (method.getName().equals("setState")) {
                        ((InputStream) args[args.length - 1]).close();
                    }
                    try {
                        return method.invoke(object, args);
                    } catch (InvocationTargetException e) {
                        throw e.getCause();
                    }
                }
            });
            return or.replicate(id, iface, o, startTimeout);
        }
    });
    deployLargeVDB(server2);
    Connection c2 = server2.createConnection("jdbc:teiid:large");
    Statement stmt2 = c2.createStatement();
    ResultSet rs2 = stmt2.executeQuery("select * from matviews where name = 'c'");
    assertTrue(rs2.next());
    assertEquals("NEEDS_LOADING", rs2.getString("loadstate"));
    stmt2 = c2.createStatement();
    rs2 = stmt2.executeQuery("select * from c");
    int rowCount2 = 0;
    while (rs2.next()) {
        rowCount2++;
    }
    assertEquals(rowCount, rowCount2);
}
Also used : Statement(java.sql.Statement) InputStream(java.io.InputStream) Connection(java.sql.Connection) ObjectReplicator(org.teiid.query.ObjectReplicator) Method(java.lang.reflect.Method) FunctionMethod(org.teiid.metadata.FunctionMethod) InvocationHandler(java.lang.reflect.InvocationHandler) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ReplicatedObject(org.teiid.query.ReplicatedObject) ResultSet(java.sql.ResultSet) ReplicatedObject(org.teiid.query.ReplicatedObject) BeforeClass(org.junit.BeforeClass) Test(org.junit.Test)

Aggregations

ObjectReplicator (org.teiid.query.ObjectReplicator)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 Replicated (org.teiid.Replicated)1 EventDistributorImpl (org.teiid.deployers.EventDistributorImpl)1 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)1 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)1 EventDistributor (org.teiid.events.EventDistributor)1 FunctionMethod (org.teiid.metadata.FunctionMethod)1 ReplicatedObject (org.teiid.query.ReplicatedObject)1 TranslatorException (org.teiid.translator.TranslatorException)1