Example usage for java.rmi Remote getClass

List of usage examples for java.rmi Remote getClass

Introduction

In this page you can find the example usage for java.rmi Remote getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.jdal.remoting.rmi.RmiServiceExporter.java

@Override
public Remote getObjectToExport() {
    Remote exportedObject = super.getObjectToExport();

    if (getService() instanceof Remote && (getServiceInterface() == null
            || exportedObject.getClass().isAssignableFrom(getServiceInterface()))) {
        this.remoteService = exportedObject;
    } else {//from  w w w .  j a va2  s. c  o  m
        // RMI Invokers. 
        ProxyFactory factory = new ProxyFactory(getServiceInterface(),
                new RmiServiceInterceptor((RmiInvocationHandler) exportedObject, remoteServiceName));

        this.remoteService = factory.getProxy();
    }

    return exportedObject;
}

From source file:de.tudarmstadt.lt.lm.app.ListServices.java

@Override
public void run() {
    String[] services = new String[] {};
    Registry registry = null;//from w w w .  j  a v  a2  s . com
    try {
        registry = LocateRegistry.getRegistry(_host, _port);
    } catch (Exception e) {
        LOG.error("Could not connect to registry.", e);
        System.exit(1);
    }
    try {
        services = registry.list();
    } catch (Exception e) {
        LOG.error("Could not lookup services from registry.", e);
        System.exit(1);
    }

    LOG.info("{} services available.", services.length);

    for (String name : services) {
        Remote r = null;
        try {
            r = registry.lookup(name);
        } catch (NotBoundException | RemoteException e) {
            continue;
        }
        StringBuilder b = new StringBuilder();
        for (Class<?> clazz : r.getClass().getInterfaces())
            b.append(", ").append(clazz.getName());
        String status = "status:unknown";
        try {
            if (r instanceof StringProviderMXBean)
                status = ((StringProviderMXBean) r).getModelReady() ? "status:running" : "status:loading";
        } catch (RemoteException e) {
        }
        System.out.format("%s\t(%s)\t[%s] %n", name, b.length() > 0 ? b.substring(2) : "", status);
    }
}

From source file:org.globus.workspace.remoting.RemotingServer.java

public void initialize() throws RemoteException, AlreadyBoundException {
    if (this.socketDirectory == null) {
        throw new IllegalStateException("socketDirectory must be specified");
    }//from  w  w w  .j  ava  2  s .c o m
    if (!this.socketDirectory.isDirectory()) {
        throw new IllegalStateException(
                "socketDirectory must be an existing directory: " + this.socketDirectory.getAbsolutePath());
    }

    if (this.bindings == null || this.bindings.isEmpty()) {
        throw new IllegalStateException("at least one binding must be specified");
    }

    final AFUNIXNaming naming = AFUNIXNaming.getInstance(this.socketDirectory);
    logger.debug("Socket directory: " + naming.getSocketFactory().getSocketDir());

    // this trick allows repeated initializations within the same JVM. (like during test runs)
    Registry registry;
    try {
        registry = naming.createRegistry();
    } catch (RemoteException e) {
        registry = naming.getRegistry();
    }

    final StringBuilder logMessage = new StringBuilder();
    logMessage.append("Nimbus remoting server listening on domain socket: \"")
            .append(this.socketDirectory.getAbsolutePath()).append("\". Bindings:");

    boolean first = true;
    for (final String bindingName : bindings.keySet()) {
        final Remote obj = bindings.get(bindingName);
        if (obj == null) {
            throw new IllegalStateException("Binding object " + bindingName + "' is null");
        }

        logger.debug("Binding " + obj.toString() + " to name '" + bindingName + "'");

        final Remote remote = UnicastRemoteObject.exportObject(obj, 0, naming.getSocketFactory(),
                naming.getSocketFactory());
        try {
            registry.bind(bindingName, remote);
        } catch (AlreadyBoundException e) {
            logger.warn("RMI binding '" + bindingName + "' is already bound. Proceeding.");
        }

        if (first) {
            first = false;
        } else {
            logMessage.append(",");
        }
        logMessage.append(" ").append(bindingName).append(" (").append(obj.getClass().getCanonicalName())
                .append(")");
    }

    logger.info(logMessage.toString());
}

From source file:org.mule.transport.rmi.RmiConnector.java

/**
 * Helper method for Dispatchers and Receives to extract the correct method from
 * a Remote object//from w ww.  ja  v  a  2 s.com
 *
 * @param remoteObject The remote object on which to invoke the method
 * @param event The current event being processed
 * @throws org.mule.api.MuleException
 * @throws NoSuchMethodException
 * @throws ClassNotFoundException
 */
public Method getMethodObject(Remote remoteObject, MuleEvent event, OutboundEndpoint outboundEndpoint)
        throws MuleException, NoSuchMethodException, ClassNotFoundException {
    EndpointURI endpointUri = outboundEndpoint.getEndpointURI();
    String methodName = MapUtils.getString(endpointUri.getParams(), MuleProperties.MULE_METHOD_PROPERTY, null);

    if (null == methodName) {
        methodName = (String) event.getMessage().removeProperty(MuleProperties.MULE_METHOD_PROPERTY,
                PropertyScope.INVOCATION);

        if (null == methodName) {
            throw new MessagingException(RmiMessages.messageParamServiceMethodNotSet(), event);
        }
    }

    Class[] argTypes = getArgTypes(
            event.getMessage().getInvocationProperty(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES), event);

    try {
        return remoteObject.getClass().getMethod(methodName, argTypes);
    } catch (NoSuchMethodException e) {
        throw new NoSuchMethodException(CoreMessages.methodWithParamsNotFoundOnObject(methodName,
                ArrayUtils.toString(argTypes), remoteObject.getClass()).toString());
    } catch (SecurityException e) {
        throw e;
    }
}