Example usage for org.springframework.remoting.rmi RmiProxyFactoryBean setServiceInterface

List of usage examples for org.springframework.remoting.rmi RmiProxyFactoryBean setServiceInterface

Introduction

In this page you can find the example usage for org.springframework.remoting.rmi RmiProxyFactoryBean setServiceInterface.

Prototype

public void setServiceInterface(Class<?> serviceInterface) 

Source Link

Document

Set the interface of the service to access.

Usage

From source file:com.rk.grid.cluster.slave.NodeMain.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
    String host = "localhost";
    String port = null;//from  w w  w  .  j a  va 2 s.c om
    int indx = 0;
    String serviceName = null;
    System.out.println("Node bootstrap params: " + Arrays.asList(args));
    while (indx < args.length && args[indx].startsWith("-")) {
        if (args[indx].equalsIgnoreCase("-p")) {
            port = args[++indx];
            log("Port=" + port);
        } else if (args[indx].equalsIgnoreCase("-h")) {
            host = args[++indx];
            log("Host=" + host);
        } else if (args[indx].equalsIgnoreCase("-b")) {
            serviceName = args[++indx];
            log("Broker ServiceName=" + serviceName);
        }
        indx++;
    }

    if (port == null) {
        throw new RuntimeException("Port not set");
    }

    if (serviceName == null) {
        throw new RuntimeException("Broker Service Name not set");
    }

    RmiProxyFactoryBean s = new RmiProxyFactoryBean();
    s.setServiceUrl("rmi://" + host + ":" + port + "/" + serviceName);
    s.setServiceInterface(IBroker.class);
    s.afterPropertiesSet();

    IBroker<Object> broker = (IBroker<Object>) s.getObject();

    RemoteExecutorNode<Object> remoteExecutor = new RemoteExecutorNode<Object>(broker);

    GridConfig gridConfig = broker.getBrokerInfo().getConfig();

    if (gridConfig.libraryPathDefined()) {
        String libraryPath = gridConfig.getLibraryPath();
        ClassLoader loader = getClassLoader(libraryPath);
        Thread.currentThread().setContextClassLoader(loader);
    }

    InjectionInterceptor interceptor = new InjectionInterceptor();

    if (gridConfig.injectionContextDefined()) {
        String injectionContext = gridConfig.getInjectionContext();
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(injectionContext);
        interceptor.setContext(ctx);
    }

    interceptor.addBean("monitor", broker.getProgressMonitor());

    remoteExecutor.add(interceptor);

    remoteExecutor.start();
}

From source file:com.mysoft.b2b.event.scheduler.protocol.rmi.RMIClientHelper.java

public static ProtocolService getRMIProtocolService(String protocolUrl) {
    String serviceUrl = "";
    if (protocolUrl != null && protocolUrl.endsWith("/")) {
        serviceUrl = protocolUrl;/*from   w  w  w .ja va2  s  .  co  m*/
    } else {
        serviceUrl = protocolUrl + "/";
    }
    serviceUrl = serviceUrl + ProtocolService.class.getSimpleName();
    RmiProxyFactoryBean rpfb = new RmiProxyFactoryBean();
    rpfb.setServiceUrl(serviceUrl);
    rpfb.setServiceInterface(ProtocolService.class);
    try {
        rpfb.setLookupStubOnStartup(false);
        rpfb.setRefreshStubOnConnectFailure(true);
        rpfb.afterPropertiesSet();
    } catch (Exception e) {
        logger.info("Can't get the remote RMI server: " + serviceUrl + ", because " + e.getMessage());
        return null;
    }
    logger.info("Success to init RMI local proxy service for " + serviceUrl);
    return (ProtocolService) rpfb.getObject();
}

From source file:com.rk.grid.federation.FederatedCluster.java

@SuppressWarnings("unchecked")
private static IBroker<Object> getConnection(String serviceName, int port, String host) {
    RmiProxyFactoryBean s = new RmiProxyFactoryBean();
    s.setServiceUrl("rmi://" + host + ":" + port + "/" + serviceName);
    s.setServiceInterface(IBroker.class);
    s.afterPropertiesSet();// w ww .  j  a  va  2 s .c om

    IBroker<Object> broker = (IBroker<Object>) s.getObject();
    return broker;
}

From source file:au.com.jwatmuff.genericp2p.rmi.RMIPeerManager.java

@SuppressWarnings("unchecked")
private static <T> T getService(InetSocketAddress address, String serviceName, Class<T> serviceClass)
        throws NoSuchServiceException {
    String url = "rmi://" + address.getHostName() + ":" + address.getPort() + "/" + serviceName;
    try {/*from ww  w  . j ava 2 s . co m*/
        /* maybe should use address.getAddress().getHostAddress() */
        RmiProxyFactoryBean factory = new RmiProxyFactoryBean();
        factory.setServiceInterface(serviceClass);
        factory.setServiceUrl(url);
        factory.afterPropertiesSet();
        return (T) factory.getObject();
    } catch (RemoteLookupFailureException rlfe) {
        throw new NoSuchServiceException("Unable to resolve service " + serviceName + " at url: " + url);
    } catch (Exception e) {
        throw new RuntimeException("getService failed", e);
    }
}

From source file:com.apress.prospringintegration.springenterprise.stocks.client.RMIClientConfig.java

@Bean
public QuoteService quoteServiceBean() {
    RmiProxyFactoryBean factory = new RmiProxyFactoryBean();
    factory.setServiceUrl("rmi://localhost:1099/QuoteService");
    factory.setServiceInterface(QuoteService.class);
    factory.afterPropertiesSet();/*  w w w  .  ja  v  a  2  s. c  om*/
    return (QuoteService) factory.getObject();
}

From source file:net.dfs.remote.main.ClientServicesStarter.java

public RemoteNodeRegistration startProxy() {

    RmiProxyFactoryBean proxyFactory = new RmiProxyFactoryBean();
    proxyFactory.setServiceUrl("rmi://" + props.getProperty("server.ip") + ":8989/RemoteNodeRegistration");
    proxyFactory.setServiceInterface(RemoteNodeRegistration.class);
    proxyFactory.afterPropertiesSet();/*from   w  w  w.ja v  a 2 s  . com*/

    return (RemoteNodeRegistration) proxyFactory.getObject();
}