Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
commit
e2085cb4a6
|
@ -1,9 +1,13 @@
|
|||
package com.baeldung.caffeine;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
final class DataObject {
|
||||
private final String data;
|
||||
|
||||
private static int objectCounter = 0;
|
||||
private static final Logger log = LoggerFactory.getLogger(DataObject.class);
|
||||
|
||||
private DataObject(String data) {
|
||||
this.data = data;
|
||||
|
@ -22,7 +26,7 @@ final class DataObject {
|
|||
|
||||
public static DataObject get(String data) {
|
||||
objectCounter++;
|
||||
System.out.println(String.format("Initializing DataObject#%d with data '%s'", objectCounter, data));
|
||||
log.info("Init DataObject#{} with '{}'", objectCounter, data);
|
||||
return new DataObject(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
grant {
|
||||
permission java.security.AllPermission;
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
grant {
|
||||
permission java.security.AllPermission;
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
package org.baeldung;
|
||||
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
public class Client {
|
||||
public static void main(String[] args) throws RemoteException, NotBoundException {
|
||||
System.setProperty("java.security.policy", "file:./client.policy");
|
||||
if (System.getSecurityManager() == null) {
|
||||
System.setSecurityManager(new SecurityManager());
|
||||
}
|
||||
String name = "RandomNumberGenerator";
|
||||
Registry registry = LocateRegistry.getRegistry();
|
||||
RandomNumberGenerator randomNumberGenerator = (RandomNumberGenerator) registry.lookup(name);
|
||||
int number = randomNumberGenerator.get();
|
||||
System.out.println("Received random number:" + number);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.baeldung;
|
||||
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public interface RandomNumberGenerator extends Remote{
|
||||
int get() throws RemoteException;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.baeldung;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public class RandomNumberGeneratorEngine implements RandomNumberGenerator {
|
||||
@Override
|
||||
public int get() throws RemoteException {
|
||||
return (int) (100 * Math.random());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.baeldung;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
public class Server {
|
||||
public static void main(String[] args) throws RemoteException {
|
||||
System.setProperty("java.security.policy", "file:./server.policy");
|
||||
if (System.getSecurityManager() == null) {
|
||||
System.setSecurityManager(new SecurityManager());
|
||||
}
|
||||
String name = "RandomNumberGenerator";
|
||||
RandomNumberGenerator randomNumberGenerator = new RandomNumberGeneratorEngine();
|
||||
RandomNumberGenerator stub =
|
||||
(RandomNumberGenerator) UnicastRemoteObject.exportObject(randomNumberGenerator, 0);
|
||||
Registry registry = LocateRegistry.getRegistry();
|
||||
registry.rebind(name, stub);
|
||||
System.out.println("RandomNumberGenerator bound");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue