java.rmi.registry.Registry类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中java.rmi.registry.Registry类的一些代码示例,展示了Registry类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Registry类的具体详情如下:
包路径:java.rmi.registry.Registry
类名称:Registry

Registry介绍

[英]Registry is a remote interface to a simple remote object registry that provides methods for storing and retrieving remote object references bound with arbitrary string names. The bind, unbind, and rebind methods are used to alter the name bindings in the registry, and the lookup and list methods are used to query the current name bindings.

A Registry implementation may choose to restrict access to some or all of its methods (for example, methods that mutate the registry's bindings may be restricted to calls originating from the local host). If a Registry method chooses to deny access for a given invocation, its implementation may throw java.rmi.AccessException.

The names used for bindings in a Registry are pure strings, not parsed. A service which stores its remote reference in a Registry may wish to use a package name as a prefix in the name binding to reduce the likelihood of name collisions in the registry.
[中]Registry是一个简单远程对象注册表的远程接口,该注册表提供了存储和检索与任意字符串名绑定的远程对象引用的方法。bindunbindrebind方法用于更改注册表中的名称绑定,lookuplist方法用于查询当前的名称绑定。
Registry实现可能会选择限制对其部分或全部方法的访问(例如,改变注册表绑定的方法可能会被限制为来自本地主机的调用)。如果Registry方法选择拒绝对给定调用的访问,其实现可能会抛出java。rmi。访问例外。
Registry中用于绑定的名称是纯字符串,未经解析。将远程引用存储在Registry中的服务可能希望在名称绑定中使用包名作为前缀,以减少注册表中名称冲突的可能性。

代码示例

代码示例来源:origin: stackoverflow.com

final Remote remote = UnicastRemoteObject.exportObject(toBeStubbed, 0);
final Registry registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
registry.bind(REMOTE_NAME, remote);
final Registry registry = LocateRegistry.getRegistry();
final Remote remote = registry.lookup(REMOTE_NAME);
final RemoteOperations stub = RemoteOperations.class.cast(remote);
final String message = stub.remoteOperation();

代码示例来源:origin: quartz-scheduler/quartz

.exportObject(this, resources.getRMIServerPort());
} else {
  exportable = (RemotableQuartzScheduler) UnicastRemoteObject
    .exportObject(this);
    registry = LocateRegistry.getRegistry(resources
        .getRMIRegistryPort());
    registry.list();
  } catch (Exception e) {
    registry = LocateRegistry.createRegistry(resources
        .getRMIRegistryPort());
    QuartzSchedulerResources.CREATE_REGISTRY_ALWAYS)) {
  try {
    registry = LocateRegistry.createRegistry(resources
        .getRMIRegistryPort());
  } catch (Exception e) {
registry.rebind(bindName, exportable);

代码示例来源:origin: quartz-scheduler/quartz

/**
 * <p>
 * Un-bind the scheduler from an RMI registry.
 * </p>
 */
private void unBind() throws RemoteException {
  String host = resources.getRMIRegistryHost();
  // don't un-export if we're not configured to do so...
  if (host == null || host.length() == 0) {
    return;
  }
  Registry registry = LocateRegistry.getRegistry(resources
      .getRMIRegistryHost(), resources.getRMIRegistryPort());
  String bindName = resources.getRMIBindName();
  
  try {
    registry.unbind(bindName);
    UnicastRemoteObject.unexportObject(this, true);
  } catch (java.rmi.NotBoundException nbe) {
  }
  getLog().info("Scheduler un-bound from name '" + bindName + "' in RMI registry");
}

代码示例来源:origin: spring-projects/spring-framework

UnicastRemoteObject.exportObject(
    this.exportedObject, this.servicePort, this.clientSocketFactory, this.serverSocketFactory);
UnicastRemoteObject.exportObject(this.exportedObject, this.servicePort);
  this.registry.rebind(this.serviceName, this.exportedObject);
  this.registry.bind(this.serviceName, this.exportedObject);

代码示例来源:origin: stackoverflow.com

Registry registry = LocateRegistry.getRegistry("<JMX server IP address>", comSunManagementJmxRemotePort);
String[] names = registry.list();
for (String name : names) {
  System.out.println("In the registry: " + name);
RMIServer jmxrmiServer = (RMIServer)registry.lookup("jmxrmi");
System.out.println(jmxrmiServer.toString());

代码示例来源:origin: quartz-scheduler/quartz

protected RemotableQuartzScheduler getRemoteScheduler()
  throws SchedulerException {
  if (rsched != null) {
    return rsched;
  }
  try {
    Registry registry = LocateRegistry.getRegistry(rmiHost, rmiPort);
    rsched = (RemotableQuartzScheduler) registry.lookup(schedId);
  } catch (Exception e) {
    SchedulerException initException = new SchedulerException(
        "Could not get handle to remote scheduler: "
            + e.getMessage(), e);
    throw initException;
  }
  return rsched;
}

代码示例来源:origin: konsoletyper/teavm

BuildDaemon(boolean incremental) throws RemoteException {
  super();
  this.incremental = incremental;
  Random random = new Random();
  for (int i = 0; i < 20; ++i) {
    port = random.nextInt(MAX_PORT - MIN_PORT) + MIN_PORT;
    try {
      registry = LocateRegistry.createRegistry(port);
    } catch (RemoteException e) {
      continue;
    }
    try {
      registry.bind(RemoteBuildService.ID, this);
    } catch (RemoteException | AlreadyBoundException e) {
      throw new IllegalStateException("Could not bind remote build assistant service", e);
    }
    setupIncrementalCache();
    return;
  }
  throw new IllegalStateException("Could not create RMI registry");
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Start the rmiregistry.
 * <p>
 * The alternative is to use the <code>rmiregistry</code> binary, in which case:
 * <ol>
 * <li>rmiregistry running
 * <li>-Djava.rmi.server.codebase="file:///Users/gluck/work/ehcache/build/classes/ file:///Users/gluck/work/ehcache/lib/commons-logging-1.0.4.jar"
 * </ol>
 *
 * @throws RemoteException
 */
protected void startRegistry() throws RemoteException {
  try {
    registry = LocateRegistry.getRegistry(port.intValue());
    try {
      registry.list();
    } catch (RemoteException e) {
      //may not be created. Let's create it.
      registry = LocateRegistry.createRegistry(port.intValue());
      registryCreated = true;
    }
  } catch (ExportException exception) {
    LOG.error("Exception starting RMI registry. Error was " + exception.getMessage(), exception);
  }
}

代码示例来源:origin: groupon/odo

public void stopServer() {
    try {
      registry.unbind(SERVICE_NAME);
      UnicastRemoteObject.unexportObject(registry, true);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: stackoverflow.com

import java.rmi.*;
import java.rmi.registry.*;
import java.io.*;

public class RMIServer{

 public static void main(String[] argv) throws Exception{

  StackImp s = new StackImp(10);
  Registry reg = LocateRegistry.createRegistry(2000);
  reg.rebind("xyz", s);
  System.out.println("RMI Server ready....");
  System.out.println("Waiting for Request...");   

 }
}

代码示例来源:origin: org.ops4j.pax.swissbox/pax-swissbox-framework

private void export() throws RemoteException, AccessException
{
  String port = System.getProperty( RMI_PORT_KEY, "1099" );
  name = System.getProperty( RMI_NAME_KEY );
  timeout = Long.parseLong( System.getProperty( TIMEOUT_KEY, "10000") );
  String address = InetAddress.getLoopbackAddress().getHostAddress();
  registry = LocateRegistry.getRegistry( address, Integer.parseInt( port ) );
  URL location1 = getClass().getProtectionDomain().getCodeSource().getLocation();
  URL location2 = Bundle.class.getProtectionDomain().getCodeSource().getLocation();
  URL location3 = ServiceLookup.class.getProtectionDomain().getCodeSource().getLocation();
  System.setProperty( "java.rmi.server.codebase", location1 + " " + location2 + " "
      + location3 );
  Remote remote = UnicastRemoteObject.exportObject( this, 0 );
  registry.rebind( name, remote );
}

代码示例来源:origin: octo-online/reactive-audit

@Test(expected = NetworkReactiveAuditException.class)
public void lookup()
    throws NotBoundException, RemoteException
{
  TestTools.strict.commit();
  LocateRegistry.createRegistry(RMIPORT);
  LocateRegistry.getRegistry().lookup("abc");
}

代码示例来源:origin: edu.stanford.protege/org.protege.owl.server

@Override
public void start(Server server) throws IOException {
  registry = LocateRegistry.createRegistry(rmiRegistryPort);
  exportedServer = new RemoteServerImpl(server);
  UnicastRemoteObject.exportObject(exportedServer, serverPort);
  ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    registry.rebind(SERVER_NAME, exportedServer);
  }
  finally {
    Thread.currentThread().setContextClassLoader(oldClassLoader);
  }
  logger.info("Server advertised via rmi on port " + rmiRegistryPort);
  logger.info("Server exported via rmi on port " + serverPort);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-coref-ace

/** Bind this object to the value of <code>BINDING_NAME</code> in the local RMI
 * registry.
 * @exception AlreadyBoundException If <code>BINDING_NAME</code> is already bound.
 * @exception RemoteException If remote operation failed.
 */
public void bind() throws RemoteException, AlreadyBoundException {
  Registry registry = LocateRegistry.getRegistry();
  registry.bind(BINDING_NAME, this);
}

代码示例来源:origin: frohoff/ysoserial

public static void main(final String[] args) throws Exception {
  final String host = args[0];
  final int port = Integer.parseInt(args[1]);
  final String command = args[3];
  Registry registry = LocateRegistry.getRegistry(host, port);
  final String className = CommonsCollections1.class.getPackage().getName() +  "." + args[2];
  final Class<? extends ObjectPayload> payloadClass = (Class<? extends ObjectPayload>) Class.forName(className);
  // test RMI registry connection and upgrade to SSL connection on fail
  try {
    registry.list();
  } catch(ConnectIOException ex) {
    registry = LocateRegistry.getRegistry(host, port, new RMISSLClientSocketFactory());
  }
  // ensure payload doesn't detonate during construction or deserialization
  exploit(registry, payloadClass, command);
}

代码示例来源:origin: stackoverflow.com

Registry registry =
   LocateRegistry.getRegistry("localhost",
                 Registry.REGISTRY_PORT);
 EchoServer es = (EchoServer)registry.lookup("echo");
 System.err.println("es: " + es);
 System.out.println(es.echo("hallo"));

代码示例来源:origin: spring-projects/spring-framework

/**
 * Test the given RMI registry, calling some operation on it to
 * check whether it is still active.
 * <p>Default implementation calls {@code Registry.list()}.
 * @param registry the RMI registry to test
 * @throws RemoteException if thrown by registry methods
 * @see java.rmi.registry.Registry#list()
 */
protected void testRegistry(Registry registry) throws RemoteException {
  registry.list();
}

代码示例来源:origin: stackoverflow.com

Controle obj = new Controle(4);
Controle stub = (Controle) UnicastRemoteObject.exportObject(obj, 0);
Registry reg = LocateRegistry.createRegistry(1099);
System.out.println("Server is ready");
reg.rebind("CtrlServ", stub);

代码示例来源:origin: spring-projects/spring-framework

/**
 * Unbind the RMI service from the registry on bean factory shutdown.
 */
@Override
public void destroy() throws RemoteException {
  if (logger.isDebugEnabled()) {
    logger.debug("Unbinding RMI service '" + this.serviceName +
        "' from registry" + (this.createdRegistry ? (" at port '" + this.registryPort + "'") : ""));
  }
  try {
    this.registry.unbind(this.serviceName);
  }
  catch (NotBoundException ex) {
    if (logger.isInfoEnabled()) {
      logger.info("RMI service '" + this.serviceName + "' is not bound to registry" +
          (this.createdRegistry ? (" at port '" + this.registryPort + "' anymore") : ""), ex);
    }
  }
  finally {
    unexportObjectSilently();
  }
}

代码示例来源:origin: stackoverflow.com

Remote server =
   UnicastRemoteObject.exportObject(new EchoServerImpl(),
                    0, fac, fac);
 System.err.println("server: " + server);
 Registry registry =
   LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
 registry.bind("echo", server);

相关文章