use of java.rmi.registry.Registry in project karaf by apache.
the class RmiRegistryFactory method destroy.
public void destroy() throws RemoteException {
if (registry != null && locallyCreated) {
Registry reg = registry;
registry = null;
UnicastRemoteObject.unexportObject(reg, true);
// clear TCPEndpointCache
try {
Class<?> cls = getClass().getClassLoader().loadClass("sun.rmi.transport.tcp.TCPEndpoint");
Field localEndpointsField = cls.getDeclaredField("localEndpoints");
Field ssfField = cls.getDeclaredField("ssf");
localEndpointsField.setAccessible(true);
ssfField.setAccessible(true);
Object localEndpoints = localEndpointsField.get(null);
if (localEndpoints != null) {
Map<Object, Object> map = (Map<Object, Object>) localEndpoints;
for (Iterator<Object> it = map.keySet().iterator(); it.hasNext(); ) {
Object key = it.next();
Object ssf = ssfField.get(key);
if (ssf != null && ssf.getClass().getPackage().getName().equals("org.apache.karaf.management")) {
it.remove();
}
}
}
} catch (Exception ignored) {
}
}
}
use of java.rmi.registry.Registry in project jmeter by apache.
the class RemoteJMeterEngineImpl method init.
private void init() throws RemoteException {
log.info("Starting backing engine on {}", this.rmiPort);
InetAddress localHost = null;
// Bug 47980 - allow override of local hostname
// $NON-NLS-1$
String host = System.getProperties().getProperty("java.rmi.server.hostname");
try {
if (host == null) {
log.info("System property 'java.rmi.server.hostname' is not defined, using localHost address");
localHost = InetAddress.getLocalHost();
} else {
log.info("Resolving by name the value of System property 'java.rmi.server.hostname': {}", host);
localHost = InetAddress.getByName(host);
}
} catch (UnknownHostException e1) {
throw new RemoteException("Cannot start. Unable to get local host IP address.", e1);
}
if (log.isInfoEnabled()) {
log.info("Local IP address={}", localHost.getHostAddress());
}
// BUG 52469 : Allow loopback address for SSH Tunneling of RMI traffic
if (host == null && localHost.isLoopbackAddress()) {
String hostName = localHost.getHostName();
throw new RemoteException("Cannot start. " + hostName + " is a loopback address.");
}
if (localHost.isSiteLocalAddress()) {
// should perhaps be log.warn, but this causes the client-server test to fail
log.info("IP address is a site-local address; this may cause problems with remote access.\n" + "\tCan be overridden by defining the system property 'java.rmi.server.hostname' - see jmeter-server script file");
}
log.debug("This = {}", this);
Registry reg = null;
if (CREATE_SERVER) {
log.info("Creating RMI registry (server.rmi.create=true)");
try {
reg = LocateRegistry.createRegistry(this.rmiPort);
log.debug("Created registry: {}", reg);
} catch (RemoteException e) {
String msg = "Problem creating registry: " + e;
log.warn(msg);
System.err.println(msg);
System.err.println("Continuing...");
}
}
try {
if (reg == null) {
log.debug("Locating registry");
reg = LocateRegistry.getRegistry(this.rmiPort);
}
log.debug("About to rebind registry: {}", reg);
reg.rebind(JMETER_ENGINE_RMI_NAME, this);
log.info("Bound to registry on port {}", this.rmiPort);
} catch (Exception ex) {
log.error("rmiregistry needs to be running to start JMeter in server mode. {}", ex.toString());
// Throw an Exception to ensure caller knows ...
throw new RemoteException("Cannot start. See server log file.", ex);
}
}
use of java.rmi.registry.Registry in project jackrabbit by apache.
the class RepositoryStartupServlet method registerRMI.
/**
* Registers the repository to an RMI registry configured in the web
* application. See <a href="#registerAlgo">Registration with RMI</a> in the
* class documentation for a description of the algorithms used to register
* the repository with an RMI registry.
* @throws ServletException if an error occurs.
*/
private void registerRMI() {
RMIConfig rc = config.getRmiConfig();
if (!rc.isValid() || !rc.enabled()) {
return;
}
// try to create remote repository
Remote remote;
try {
Class<?> clazz = Class.forName(getRemoteFactoryDelegaterClass());
RemoteFactoryDelegater rmf = (RemoteFactoryDelegater) clazz.newInstance();
remote = rmf.createRemoteRepository(repository);
} catch (RemoteException e) {
log.warn("Unable to create RMI repository.", e);
return;
} catch (Throwable t) {
log.warn("Unable to create RMI repository." + " The jcr-rmi jar might be missing.", t);
return;
}
try {
System.setProperty("java.rmi.server.useCodebaseOnly", "true");
Registry reg = null;
// or if the rmiHost is not local
try {
// find the server socket factory: use the default if the
// rmiHost is not configured
RMIServerSocketFactory sf;
if (rc.getRmiHost().length() > 0) {
log.debug("Creating RMIServerSocketFactory for host " + rc.getRmiHost());
InetAddress hostAddress = InetAddress.getByName(rc.getRmiHost());
sf = getRMIServerSocketFactory(hostAddress);
} else {
// have the RMI implementation decide which factory is the
// default actually
log.debug("Using default RMIServerSocketFactory");
sf = null;
}
// create a registry using the default client socket factory
// and the server socket factory retrieved above. This also
// binds to the server socket to the rmiHost:rmiPort.
reg = LocateRegistry.createRegistry(rc.rmiPort(), null, sf);
rmiRegistry = reg;
} catch (UnknownHostException uhe) {
// thrown if the rmiHost cannot be resolved into an IP-Address
// by getRMIServerSocketFactory
log.info("Cannot create Registry", uhe);
} catch (RemoteException e) {
// thrown by createRegistry if binding to the rmiHost:rmiPort
// fails, for example due to rmiHost being remote or another
// application already being bound to the port
log.info("Cannot create Registry", e);
}
// registry is actually accessible.
if (reg == null) {
log.debug("Trying to access existing registry at " + rc.getRmiHost() + ":" + rc.getRmiPort());
try {
reg = LocateRegistry.getRegistry(rc.getRmiHost(), rc.rmiPort());
} catch (RemoteException re) {
log.warn("Cannot create the reference to the registry at " + rc.getRmiHost() + ":" + rc.getRmiPort(), re);
}
}
// rmiName
if (reg != null) {
log.debug("Registering repository as " + rc.getRmiName() + " to registry " + reg);
reg.bind(rc.getRmiName(), remote);
// when successfull, keep references
this.rmiRepository = remote;
log.info("Repository bound via RMI with name: " + rc.getRmiUri());
} else {
log.info("RMI registry missing, cannot bind repository via RMI");
}
} catch (RemoteException e) {
log.warn("Unable to bind repository via RMI: " + rc.getRmiUri(), e);
} catch (AlreadyBoundException e) {
log.warn("Unable to bind repository via RMI: " + rc.getRmiUri(), e);
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class RmiRegistrySslTest method main.
public static void main(String[] args) throws Exception {
System.out.println("RmiRegistry lookup...");
String testID = System.getProperty("testID");
if ("Test1".equals(testID)) {
try {
Registry registry = LocateRegistry.getRegistry(4444);
String[] list = registry.list();
if ("jmxrmi".equals(list[0])) {
System.out.println(ok);
} else {
System.out.println(ko);
throw new IllegalArgumentException(ko);
}
} catch (Exception e) {
System.out.println(koException);
e.printStackTrace(System.out);
throw e;
}
}
if ("Test2".equals(testID)) {
try {
Registry registry = LocateRegistry.getRegistry(4444);
String[] list = registry.list();
throw new IllegalArgumentException(ko2);
} catch (Exception e) {
System.out.println(okException);
e.printStackTrace(System.out);
return;
}
}
if ("Test3".equals(testID)) {
try {
Registry registry = LocateRegistry.getRegistry(null, 4444, new SslRMIClientSocketFactory());
String[] list = registry.list();
if ("jmxrmi".equals(list[0])) {
System.out.println(ok);
} else {
System.out.println(ko);
throw new IllegalArgumentException(ko);
}
} catch (Exception e) {
System.out.println(koException);
e.printStackTrace(System.out);
throw e;
}
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class MapNullValuesTest method main.
public static void main(String[] args) throws Exception {
int errorCount = 0;
MapNullValuesTest test = new MapNullValuesTest();
// Create an RMI registry
//
echo("");
echo(dashedMessage("Start RMI registry"));
Registry reg = null;
port = 7500;
while (port++ < 7550) {
try {
reg = LocateRegistry.createRegistry(port);
echo("\nRMI registry running on port " + port);
break;
} catch (RemoteException e) {
// Failed to create RMI registry...
//
echo("\nFailed to create RMI registry on port " + port);
e.printStackTrace(System.out);
}
}
if (reg == null) {
System.exit(1);
}
// Run tests
//
errorCount += test.mapToHashtableTests();
errorCount += test.jmxConnectorServerFactoryTests();
errorCount += test.jmxConnectorFactoryTests();
errorCount += test.nullKeyFactoryTests();
if (errorCount == 0) {
echo("\nNull values for key/value pairs in Map Tests PASSED!");
} else {
echo("\nNull values for key/value pairs in Map Tests FAILED!");
System.exit(1);
}
}
Aggregations