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;
}
});
}
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;
}
}
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);
}
Aggregations