use of java.rmi.AlreadyBoundException in project jdk8u_jdk by JetBrains.
the class Main method setupServer.
/**
* Setup benchmark server.
*/
static void setupServer() {
switch(runmode) {
case SAMEVM:
try {
serverImpl = new BenchServerImpl();
server = (BenchServer) RemoteObject.toStub(serverImpl);
} catch (RemoteException e) {
die("Error: failed to create local server: " + e);
}
if (verbose)
System.out.println("Benchmark server created locally");
break;
case CLIENT:
try {
Registry reg = LocateRegistry.getRegistry(host, port);
server = (BenchServer) reg.lookup(REGNAME);
} catch (NotBoundException | RemoteException e) {
die("Error: failed to connect to server: " + e);
}
if (server == null) {
die("Error: server not found");
}
if (verbose) {
System.out.println("Connected to benchmark server on " + host + ":" + port);
}
break;
case SERVER:
try {
Registry reg = LocateRegistry.createRegistry(port);
serverImpl = new BenchServerImpl();
reg.bind(REGNAME, serverImpl);
} catch (AlreadyBoundException | RemoteException e) {
die("Error: failed to initialize server: " + e);
}
if (verbose) {
System.out.println("Benchmark server started on port " + port);
}
break;
default:
throw new InternalError("illegal runmode");
}
}
use of java.rmi.AlreadyBoundException in project jackrabbit-oak 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.AlreadyBoundException in project mlib by myshzzx.
the class RMITest2 method server.
@Test
public void server() throws RemoteException, AlreadyBoundException, InterruptedException {
Registry registry = LocateRegistry.createRegistry(port);
BlockingQueue<Socket> socks = new LinkedBlockingQueue<>();
RIImpl ro = new RIImpl();
Remote expRO = UnicastRemoteObject.exportObject(ro, port + 1, null, p -> new ServerSocket(p) {
@Override
public Socket accept() throws IOException {
final Socket accept = super.accept();
socks.offer(accept);
return accept;
}
});
registry.bind("ro", expRO);
new Thread() {
@Override
public void run() {
Socket sock;
while (true) {
try {
Thread.sleep(500);
sock = socks.take();
if (sock.isClosed())
System.out.println("sock closed");
else
socks.offer(sock);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}.start();
Thread.sleep(100000000);
}
use of java.rmi.AlreadyBoundException in project scheduling by ow2-proactive.
the class SchedulerStarter method startResourceManager.
private static void startResourceManager(final int numberLocalNodes, final int nodeTimeoutValue) {
final Thread rmStarter = new Thread() {
public void run() {
try {
// Starting a local RM using default deployment descriptor
RMFactory.setOsJavaProperty();
LOGGER.info("Starting the resource manager...");
RMAuthentication rmAuth = RMFactory.startLocal();
if (numberLocalNodes > 0) {
addLocalNodes(rmAuth, numberLocalNodes, nodeTimeoutValue);
}
LOGGER.info("The resource manager with " + numberLocalNodes + " local nodes created on " + rmAuth.getHostURL());
} catch (AlreadyBoundException abe) {
LOGGER.error("The resource manager already exists on local host", abe);
System.exit(4);
} catch (Exception aoce) {
LOGGER.error("Unable to create local resource manager", aoce);
System.exit(5);
}
}
};
rmStarter.start();
}
use of java.rmi.AlreadyBoundException in project che by eclipse.
the class RmiServer method start.
protected static void start(Remote remote) throws RemoteException {
System.setProperty("java.rmi.server.hostname", "localhost");
System.setProperty("java.rmi.server.disableHttp", "true");
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.eclipse.che.rmi.JNDI");
if (RmiServer.remote != null) {
throw new AssertionError("This server is already started!");
}
RmiServer.remote = remote;
int port = -1;
Random random = new Random();
Registry registry = null;
while (port == -1) {
int tmpPort = random.nextInt(65535);
if (tmpPort < 4000) {
continue;
}
try {
registry = LocateRegistry.createRegistry(tmpPort);
port = tmpPort;
} catch (ExportException ignored) {
}
}
Remote exportObject = UnicastRemoteObject.exportObject(remote, port);
String exportName = remote.getClass().getSimpleName() + Integer.toHexString(exportObject.hashCode());
try {
registry.bind(exportName, exportObject);
String portName = port + "/" + exportName;
System.out.println("Port/Name:" + portName);
int twoMinutes = 2 * 60 * 1000;
Object lock = new Object();
while (true) {
synchronized (lock) {
lock.wait(twoMinutes);
}
// TODO add ping
}
} catch (AlreadyBoundException | InterruptedException e) {
e.printStackTrace();
System.exit(42);
}
}
Aggregations