static boolean isAlreadyRunning(InvokerLocator serverLocator) { Map<String, String> metadata = new HashMap<>(); metadata.put(SocketWrapper.WRITE_TIMEOUT, String.valueOf(ConfigSettings.instance.getSocketWriteTimeout())); metadata.put("generalizeSocketException", "true"); try { MageServer testServer = (MageServer) TransporterClient.createTransporterClient(serverLocator.getLocatorURI(), MageServer.class, metadata); if (testServer != null) { testServer.getServerState(); return true; } } catch (Throwable t) { // assume server is not running } return false; }
server = (MageServer) TransporterClient.createTransporterClient(clientLocator.getLocatorURI(), MageServer.class, metadata);
public void getCustomerProcessor() throws Exception { customerProcessor = (CustomerProcessor) TransporterClient.createTransporterClient(locatorURI, CustomerProcessor.class, true); }
public static void main(String[] args) throws Exception { DateProcessor dateProcessor = (DateProcessor) TransporterClient.createTransporterClient("socket://localhost:5400", DateProcessor.class); String formattedDate = dateProcessor.formatDate(new Date()); System.out.println("Current date: " + formattedDate); } }
public void getCustomerProcessor() throws Exception { initTransporterServices(); customerProcessor = (CustomerProcessor) TransporterClient.createTransporterClient(locatorURI, CustomerProcessor.class, true); }
/** * Create a remote proxy to a POJO on a remote server. * * @param locatorURI - the remoting locator uri to the target server where the target POJO exists. * @param targetClass - the interface class of the POJO will be calling upon. * @return dynamic remote proxy typed to the interface specified by the targetClass param. * @throws Exception */ public static Object createTransporterClient(String locatorURI, Class targetClass) throws Exception { InvokerLocator locator = new InvokerLocator(locatorURI); return createTransporterClient(locator, targetClass); }
private InputStreamService getInputStreamService() throws IOException { if (_streamService == null) { if (_sourceInvokerLocator == null) { throw new IOException("remote source invoker locator was not set"); } // HQ-1638 (Use the same strategy as HQ-1572) // InputStreamService and the remoting classes for the unidirectional transport are intentionally // put into the ServerHandler classloader. As of this comment, that classloader is a peer // to the context classloader, so those classes are not visible to the current thread context, // unless we force the issue. ClassLoader currentContext = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(InputStreamService.class.getClassLoader()); try { _streamService = (InputStreamService)TransporterClient. createTransporterClient(_sourceInvokerLocator, InputStreamService.class); } catch (Exception e) { throw new IOException("Failed to connect to input stream " + "service on remote source: "+e); } finally { Thread.currentThread().setContextClassLoader(currentContext); } } return _streamService; }
public void makeClientCall() throws Exception { Customer customer = createCustomer(); CustomerProcessor customerProcessor = (CustomerProcessor) TransporterClient.createTransporterClient(locatorURI, CustomerProcessor.class); System.out.println("Customer to be processed: " + customer); Customer processedCustomer = customerProcessor.processCustomer(customer); System.out.println("Customer is now: " + processedCustomer); AccountProcessor accountProcessor = (AccountProcessor) TransporterClient.createTransporterClient(locatorURI, AccountProcessor.class); System.out.println("Asking for a new account to be created for customer."); Account account = accountProcessor.createAccount(processedCustomer); System.out.println("New account: " + account); TransporterClient.destroyTransporterClient(customerProcessor); TransporterClient.destroyTransporterClient(accountProcessor); }
public void makeClientCall() throws Exception { Order order = createOrder(); OrderProcessor orderProcessor = (OrderProcessor) TransporterClient.createTransporterClient(locatorURI, OrderProcessor.class); System.out.println("Order to be processed: " + order); Order changedOrder = orderProcessor.processOrder(order); System.out.println("Order now processed " + changedOrder); TransporterClient.destroyTransporterClient(orderProcessor); }
public void makeClientCall() throws Exception { Customer customer = createCustomer(); CustomerProcessor customerProcessor = (CustomerProcessor) TransporterClient.createTransporterClient(locatorURI, CustomerProcessor.class); System.out.println("Customer to be processed: " + customer); Customer processedCustomer = customerProcessor.processCustomer(customer); System.out.println("Customer is now: " + processedCustomer); TransporterClient.destroyTransporterClient(customerProcessor); }
public void makeClientCall() throws Exception { Customer customer = createCustomer(); CustomerProcessor customerProcessor = (CustomerProcessor) TransporterClient.createTransporterClient(locatorURI, CustomerProcessor.class); System.out.println("Customer to be processed: " + customer); ICustomer processedCustomer = customerProcessor.processCustomer(customer); // processedCustomer returned is actually a proxy to the Customer instnace // that lives on the server. So when print it out below, will actually // be calling back to the server to get the string (vi toString() call). // Notice the output of 'Customer.toString() being called.' on the server side. System.out.println("Customer is now: " + processedCustomer); TransporterClient.destroyTransporterClient(customerProcessor); }
/** * Takes the customer passed, and if not null and customer id * is less than 0, will create a new random id and set it. * The customer object returned will be the modified customer * object passed. * * @param customer * @return */ public ICustomer processCustomer(Customer customer) { if (customer != null && customer.getCustomerId() < 0) { customer.setCustomerId(new Random().nextInt(1000)); } ICustomer customerProxy = null; try { TransporterServer server = TransporterServer.createTransporterServer(locatorURI, customer, ICustomer.class.getName()); customerProxy = (ICustomer) TransporterClient.createTransporterClient(locatorURI, ICustomer.class); } catch (Exception e) { e.printStackTrace(); } System.out.println("processed customer with new id of " + customerProxy.getCustomerId()); return customerProxy; }
/** * Create a remote proxy to a POJO on a remote server. * * @param locatorURI - the remoting locator uri to the target server where the target POJO exists. * @param targetClass - the interface class of the POJO will be calling upon. * @param clustered - true will cause the transporter to look for other remoting serves that have the POJO running * and include it in the client's target list. If a call on first target fails, will seamlessly fail over to one * of the other discovered targets. * @return dynamic remote proxy typed to the interface specified by the targetClass param. * @throws Exception */ public static Object createTransporterClient(String locatorURI, Class targetClass, boolean clustered) throws Exception { if (!clustered) { return createTransporterClient(locatorURI, targetClass); } else { if (InternalTransporterServices.getInstance().getNetworkRegistry() == null) { setupDetector(); } InvokerLocator locator = new InvokerLocator(locatorURI); TransporterClient client = new TransporterClient(locator, targetClass.getName()); return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{targetClass}, client); } }
ProviderInterface providerProcessor = (ProviderInterface) TransporterClient.createTransporterClient(locatorURI, ProviderInterface.class);