use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.
the class VCellApiMain method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
if (args.length != 2) {
System.out.println("usage: VCellApiMain javascriptDir port");
System.exit(1);
}
File javascriptDir = new File(args[0]);
if (!javascriptDir.isDirectory()) {
throw new RuntimeException("javascriptDir '" + args[0] + "' is not a directory");
}
// don't validate
PropertyLoader.loadProperties();
lg.debug("properties loaded");
String portString = args[1];
// was hard-coded at 8080
Integer port = null;
try {
port = Integer.parseInt(portString);
} catch (NumberFormatException e) {
e.printStackTrace();
throw new RuntimeException("failed to parse port argument '" + portString + "'", e);
}
lg.trace("connecting to database");
lg.trace("oracle factory (next)");
ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
KeyFactory keyFactory = conFactory.getKeyFactory();
lg.trace("database impl (next)");
DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
lg.trace("local db server (next)");
LocalAdminDbServer localAdminDbServer = new LocalAdminDbServer(conFactory, keyFactory);
lg.trace("admin db server (next)");
AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
lg.trace("messaging service (next)");
VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
vcMessagingService.setDelegate(new VCMessagingDelegate() {
@Override
public void onTraceEvent(String string) {
System.out.println("Trace: " + string);
}
@Override
public void onRpcRequestSent(VCRpcRequest vcRpcRequest, UserLoginInfo userLoginInfo, VCMessage vcRpcRequestMessage) {
System.out.println("request sent:");
}
@Override
public void onRpcRequestProcessed(VCRpcRequest vcRpcRequest, VCMessage rpcVCMessage) {
System.out.println("request processed:");
}
@Override
public void onMessageSent(VCMessage message, VCDestination desintation) {
System.out.println("message sent:");
}
@Override
public void onMessageReceived(VCMessage vcMessage, VCDestination vcDestination) {
System.out.println("message received");
}
@Override
public void onException(Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}
});
lg.trace("rest database service (next)");
RestDatabaseService restDatabaseService = new RestDatabaseService(databaseServerImpl, localAdminDbServer, vcMessagingService);
lg.trace("rest event service (next)");
RestEventService restEventService = new RestEventService(vcMessagingService);
lg.trace("use verifier (next)");
UserVerifier userVerifier = new UserVerifier(adminDbTopLevel);
lg.trace("mongo (next)");
VCMongoMessage.enabled = true;
VCMongoMessage.serviceStartup(ServiceName.unknown, port, args);
System.out.println("setting up server configuration");
lg.trace("register engine (next)");
Engine.register(true);
WadlComponent component = new WadlComponent();
// Server httpServer = component.getServers().add(Protocol.HTTP, 80);
// Server httpsServer = component.getServers().add(Protocol.HTTPS, 443);
// Client httpsClient = component.getClients().add(Protocol.HTTPS);
// Client httpClient = component.getClients().add(Protocol.HTTP);
lg.trace("adding FILE protcol");
@SuppressWarnings("unused") Client httpClient = component.getClients().add(Protocol.FILE);
lg.trace("adding CLAP protcol");
@SuppressWarnings("unused") Client clapClient = component.getClients().add(Protocol.CLAP);
lg.trace("adding CLAP https");
File keystorePath = new File(PropertyLoader.getRequiredProperty(PropertyLoader.vcellapiKeystoreFile));
String keystorePassword = PropertyLoader.getSecretValue(PropertyLoader.vcellapiKeystorePswd, PropertyLoader.vcellapiKeystorePswdFile);
try {
//
// keystorePassword may be encrypted with dbPassword, if it is decypt it.
//
String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile);
SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = kf.generateSecret(new PBEKeySpec(dbPassword.toCharArray()));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(new byte[] { 32, 11, 55, 121, 01, 42, 89, 11 }, 20));
keystorePassword = new String(pbeCipher.doFinal(DatatypeConverter.parseBase64Binary(keystorePassword)));
} catch (Exception e) {
System.out.println("password unhashing didn't work - trying clear text password");
e.printStackTrace();
}
Server httpsServer = component.getServers().add(Protocol.HTTPS, port);
Series<Parameter> parameters = httpsServer.getContext().getParameters();
parameters.add("keystorePath", keystorePath.toString());
parameters.add("keystorePassword", keystorePassword);
parameters.add("keystoreType", "JKS");
parameters.add("keyPassword", keystorePassword);
parameters.add("disabledCipherSuites", "SSL_RSA_WITH_3DES_EDE_CBC_SHA " + "SSL_DHE_RSA_WITH_DES_CBC_SHA " + "SSL_DHE_DSS_WITH_DES_CBC_SHA");
parameters.add("enabledCipherSuites", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA " + "TLS_RSA_WITH_AES_128_CBC_SHA " + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA " + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA " + "TLS_RSA_WITH_AES_256_CBC_SHA");
lg.trace("create config");
Configuration templateConfiguration = new Configuration();
templateConfiguration.setObjectWrapper(new DefaultObjectWrapper());
lg.trace("verify python installation");
PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.COPASI, PythonPackage.LIBSBML, PythonPackage.THRIFT });
lg.trace("start Optimization Service");
OptServerImpl optServerImpl = new OptServerImpl();
optServerImpl.start();
lg.trace("create app");
boolean bIgnoreHostProblems = true;
boolean bIgnoreCertProblems = true;
User testUser = localAdminDbServer.getUser(TEST_USER);
// lookup hashed auth credentials in database.
UserInfo testUserInfo = localAdminDbServer.getUserInfo(testUser.getID());
HealthService healthService = new HealthService(restEventService, "localhost", port, bIgnoreCertProblems, bIgnoreHostProblems, testUserInfo.userid, testUserInfo.digestedPassword0);
AdminService adminService = new AdminService(adminDbTopLevel, databaseServerImpl);
RpcService rpcService = new RpcService(vcMessagingService);
WadlApplication app = new VCellApiApplication(restDatabaseService, userVerifier, optServerImpl, rpcService, restEventService, adminService, templateConfiguration, healthService, javascriptDir);
lg.trace("attach app");
component.getDefaultHost().attach(app);
System.out.println("component start()");
lg.trace("start component");
component.start();
System.out.println("component ended.");
lg.trace("component started");
lg.trace("start VCell Health Monitoring service");
healthService.start();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.
the class TestRPC method main.
public static void main(String[] args) throws Exception {
try {
PropertyLoader.loadProperties();
VCMessagingService messagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
messagingService.setDelegate(new SimpleMessagingDelegate());
// reading message and computing sum
// create N comsumers
MyRpcServer myRpcServer = new MyRpcServer();
VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
VCPooledQueueConsumer pooledQueueConsumer = new VCPooledQueueConsumer(rpcMessageHandler, NUM_THREADS, messagingService.createProducerSession());
pooledQueueConsumer.initThreadPool();
VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, pooledQueueConsumer, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Master Thread ", 1000);
// VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellQueue.JimQueue, log);
// VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellQueue.JimQueue, rpcMessageHandler, null, "Queue["+VCellQueue.JimQueue.getName()+"] ==== RPC Consumer Master Thread ", 1000);
messagingService.addMessageConsumer(rpcConsumer);
for (int i = 0; i < NUM_MESSAGES; i++) {
// creating one messageProducer session
final VCMessageSession messageSession = messagingService.createProducerSession();
class MyTask implements Runnable {
int msgNum;
MyTask(int msgNum) {
this.msgNum = msgNum;
}
public void run() {
try {
//
// create simple RPC request for service "Testing_Service"
//
User user = new User("schaff", new KeyValue("17"));
Integer n1 = new Integer(msgNum);
Integer n2 = new Integer(msgNum + 1);
VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "add", new Object[] { n1, n2 });
//
// send request and block for response (or timeout).
// RPC invocations don't need commits.
//
Object returnValue = messageSession.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
//
if (returnValue instanceof Integer) {
System.out.println("add(" + n1 + "," + n2 + ") ===> " + returnValue);
} else {
System.out.println("unexpected return value of " + returnValue);
}
} catch (VCMessagingInvocationTargetException e) {
e.printStackTrace(System.out);
System.out.println("the rpc service threw an exception");
e.getTargetException().printStackTrace(System.out);
} catch (VCMessagingException e) {
e.printStackTrace();
}
}
}
;
new Thread(new MyTask(i)).start();
}
Thread.sleep(2000);
System.out.println("main program calling closeAll()");
pooledQueueConsumer.shutdownAndAwaitTermination();
messagingService.close();
System.out.println("main program exiting");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.
the class TestQueues method main.
public static void main(String[] args) throws Exception {
try {
PropertyLoader.loadProperties();
VCMessagingService messagingService = new VCMessagingServiceEmbedded();
messagingService.setDelegate(new SimpleMessagingDelegate());
final Calculator calculator = new Calculator();
// creating one messageProducer session
ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
for (int i = 0; i < NUM_PRODUCERS; i++) {
sessions.add(messagingService.createProducerSession());
}
int sum = 0;
for (int i = 0; i < NUM_MESSAGES; i++) {
for (int s = 0; s < NUM_PRODUCERS; s++) {
sum++;
VCMessageSession session = sessions.get(s);
VCMessage message = session.createTextMessage("message " + i + " from session " + s);
session.sendQueueMessage(VCellTestQueue.JimQueue, message, false, 100000L);
session.commit();
}
Thread.sleep(2000);
}
System.out.println("Correct sum is " + sum);
Thread.sleep(30);
// create N comsumers
for (int i = 0; i < NUM_COMSUMERS; i++) {
QueueListener listener = new QueueListener() {
public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
// new Thread()
System.out.println("timestampMS=" + vcMessage.getTimestampMS() + ", " + toString() + ", elapsedTimeS=" + ((System.currentTimeMillis() - vcMessage.getTimestampMS()) / 1000.0) + ", Received: " + vcMessage.getTextContent());
// int number = Integer.parseInt(vcMessage.getTextContent());
calculator.add(1);
}
};
VCQueueConsumer queueConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, listener, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== Consumer Thread " + i, 1);
messagingService.addMessageConsumer(queueConsumer);
}
while (calculator.getSum() < sum) {
System.out.println("calculator sum = " + calculator.getSum());
Thread.sleep(1000);
}
System.out.println("calculator sum = " + calculator.getSum());
System.out.println("main program calling closeAll()");
messagingService.close();
System.out.println("main program exiting");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.
the class JavaSimulationExecutable method main.
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(String[] args) {
VCMessagingService vcMessagingService = null;
JavaSimulationExecutable worker = null;
try {
PropertyLoader.loadProperties();
VCMongoMessage.enabled = false;
vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
vcMessagingService.setDelegate(new ServerMessagingDelegate());
worker = new JavaSimulationExecutable(vcMessagingService, args);
worker.init();
worker.start();
} catch (Throwable ex) {
ex.printStackTrace();
if (worker != null && worker.workerEventSession != null) {
try {
WorkerEventMessage.sendFailed(worker.workerEventSession, worker, worker.simulationTask, ManageUtils.getHostName(), SimulationMessage.jobFailed(ex.getMessage()));
} catch (VCMessagingException e) {
e.printStackTrace();
}
}
} finally {
try {
if (vcMessagingService != null) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
vcMessagingService.close();
}
} catch (VCMessagingException ex) {
ex.printStackTrace(System.out);
}
System.exit(0);
}
}
use of cbit.vcell.message.VCMessagingService in project vcell by virtualcell.
the class SolverPreprocessor method sendFailureAndExit.
/**
* Starts the application.
* @param args an array of command-line arguments
* @throws VCMessagingException
*/
public static void sendFailureAndExit(HTCSolver htcSolver, SimulationTask simTask, String hostName, SimulationMessage simMessage) throws VCMessagingException {
VCMessagingService service = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
service.setDelegate(new ServerMessagingDelegate());
VCMessageSession session = service.createProducerSession();
try {
WorkerEventMessage.sendFailed(session, htcSolver, simTask, hostName, simMessage);
sleep(500);
service.close();
sleep(500);
} catch (VCMessagingException e1) {
e1.printStackTrace();
} finally {
System.exit(-1);
}
}
Aggregations