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; }
/** * @param askForReconnect - true = connection was lost because of error and * ask the user if he want to try to reconnect */ @Override public synchronized void disconnect(boolean askForReconnect) { if (isConnected()) { logger.info("DISCONNECT (still connected)"); sessionState = SessionState.DISCONNECTING; } if (connection == null || sessionState == SessionState.DISCONNECTED) { return; } try { callbackClient.removeListener(callbackHandler); callbackClient.disconnect(); TransporterClient.destroyTransporterClient(server); } catch (Throwable ex) { logger.fatal("Error disconnecting ...", ex); } if (sessionState == SessionState.DISCONNECTING || sessionState == SessionState.CONNECTING) { sessionState = SessionState.DISCONNECTED; logger.info("Disconnected ... "); if (askForReconnect) { client.showError("Network error. You have been disconnected from " + connection.getHost()); } client.disconnected(askForReconnect); // MageFrame with check to reconnect pingTime.clear(); } }
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); }
/** * 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); } }
/** * 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 loadBalancer - policy for selecting which target server to use from list of available servers. * @return dynamic remote proxy typed to the interface specified by the targetClass param. * @throws Exception */ public static Object createTransporterClient(String locatorURI, Class targetClass, LoadBalancer loadBalancer) throws Exception { if (InternalTransporterServices.getInstance().getNetworkRegistry() == null) { setupDetector(); } InvokerLocator locator = new InvokerLocator(locatorURI); TransporterClient client = new TransporterClient(locator, targetClass.getName(), loadBalancer); return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{targetClass}, client); }
String[] paramSig = createParamSignature(method.getParameterTypes()); failOver = findAlternativeTarget(); if (!failOver)
/** * Create a remote proxy to a POJO on a remote server. * * @param locator - the remoting locator 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(InvokerLocator locator, Class targetClass) throws Exception { TransporterClient client = new TransporterClient(locator, targetClass.getName()); return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{targetClass}, client); }
/** * Needs to be called by user when no longer need to make calls on remote POJO. Otherwise will * maintain remote connection until this is called. * * @param transporterClient */ public static void destroyTransporterClient(Object transporterClient) { if (transporterClient instanceof Proxy) { InvocationHandler handler = Proxy.getInvocationHandler(transporterClient); if (handler instanceof TransporterClient) { TransporterClient client = (TransporterClient) handler; client.disconnect(); } else { throw new IllegalArgumentException("Object is not a transporter client."); } } else { throw new IllegalArgumentException("Object is not a transporter client."); } }
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); }
server = (MageServer) TransporterClient.createTransporterClient(clientLocator.getLocatorURI(), MageServer.class, metadata);
/** * @see java.io.InputStream#close() */ public void close() throws IOException { if (!_closed) { _closed = true; if (_streamService != null) { TransporterClient.destroyTransporterClient(_streamService); _streamService = null; } _currentBuffer = null; } }
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); }
public void getCustomerProcessor() throws Exception { customerProcessor = (CustomerProcessor) TransporterClient.createTransporterClient(locatorURI, CustomerProcessor.class, true); }
ProviderInterface providerProcessor = (ProviderInterface) TransporterClient.createTransporterClient(locatorURI, ProviderInterface.class); TransporterClient.destroyTransporterClient(providerProcessor);
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; }
/** * 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; }