本文整理汇总了Java中java.rmi.Naming类的典型用法代码示例。如果您正苦于以下问题:Java Naming类的具体用法?Java Naming怎么用?Java Naming使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Naming类属于java.rmi包,在下文中一共展示了Naming类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectRemote
import java.rmi.Naming; //导入依赖的package包/类
private MplsnmsRmiServiceAccessPoint connectRemote(CoreConfiguration config) throws NotBoundException,
MalformedURLException, RemoteException {
if (this.ap != null) {
try {
this.ap.getServiceFacade();
return this.ap;
} catch (RemoteException e) {
log.warn("got error from existing remote [MplsnmsRmiServiceAccessPoint].", e);
this.ap = null;
}
}
MplsnmsRmiServiceAccessPoint newAccessPoint = (MplsnmsRmiServiceAccessPoint) Naming.lookup(config.getDbServerUrl());
if (newAccessPoint == null) {
throw new IllegalStateException("inventory server not found on " + config.getDbServerUrl());
}
this.ap = newAccessPoint;
registTriggers();
return ap;
}
示例2: main
import java.rmi.Naming; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length == 0) {
System.err.println("usage: RegistryInspector [registry url]");
System.exit(-1);
}
String registry = args[0];
try {
String[] names = Naming.list(registry);
for (String name : names) {
Remote remoteObject = Naming.lookup(name);
if (remoteObject != null) {
System.out.println("name[" + name + "] class=" + remoteObject.getClass().getCanonicalName());
} else {
System.out.println("name[" + name + "] is null.");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: main
import java.rmi.Naming; //导入依赖的package包/类
public static void main(String[] args) throws UnknownHostException, RemoteException, MalformedURLException{
// System.setProperty("java.rmi.server.hostname", InetAddress.getLocalHost().toString());
// System.setProperty("java.rmi.server.hostname", "172.26.210.111");
// PaymentReceiptDataService data=new PaymentReceiptData();
AccountDataService accountData=new AccountData();
CollectionReceiptDataService collectionData=new CollectionReceiptData();
CostIncomeReceiptDataService costIncomeData=new CostIncomeReceiptData();
InitialStockDataService initData=new InitialStockData();
PaymentReceiptDataService paymentData=new PaymentReceiptData();
LocateRegistry.createRegistry(8800);
//// //绑定RMI名称进行发布
Naming.rebind("rmi://localhost:8800/AccountDataService", accountData);
Naming.rebind("rmi://localhost:8800/CollectionReceiptDataService", collectionData);
Naming.rebind("rmi://localhost:8800/CostIncomeReceiptDataService", costIncomeData);
Naming.rebind("rmi://localhost:8800/InitialStockDataService", initData);
Naming.rebind("rmi://localhost:8800/PaymentReceiptDataService", paymentData);
System.out.println("Service start at 8800 !");
}
示例4: Server
import java.rmi.Naming; //导入依赖的package包/类
/**
* Register the sample company for remote invocation.
*/
public Server() {
try {
InetAddress addr = InetAddress.getLocalHost();
hostname = addr.getHostName();
} catch (UnknownHostException unknownHostException) {
System.err.println("Failure during host name resolution: " + unknownHostException);
}
try {
Naming.rebind("//" + hostname + "/meganalysis", mkSampleCompany());
} catch (RemoteException remoteException) {
System.err.println("Failure during name registration: " + remoteException);
} catch (MalformedURLException malformedException) {
System.err.println("Failure during name registration: " + malformedException);
}
}
示例5: main
import java.rmi.Naming; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
try {
int namingPort = Integer.getInteger(DUnitLauncher.RMI_PORT_PARAM).intValue();
int vmNum = Integer.getInteger(DUnitLauncher.VM_NUM_PARAM).intValue();
int pid = OSProcess.getId();
//logger.info("VM" + vmNum + " is launching" + (pid > 0? " with PID " + pid : ""));
DUnitLauncher.MasterRemote holder = (DUnitLauncher.MasterRemote) Naming.lookup("//localhost:" + namingPort + "/" + DUnitLauncher.MASTER_PARAM);
DUnitLauncher.init(holder);
DUnitLauncher.locatorPort = holder.getLocatorPort();
Naming.rebind("//localhost:" + namingPort + "/vm" + vmNum, new RemoteDUnitVM());
holder.signalVMReady();
//This loop is here so this VM will die even if the master is mean killed.
while(true) {
holder.ping();
Thread.sleep(1000);
}
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
}
示例6: ClusterImpl
import java.rmi.Naming; //导入依赖的package包/类
public ClusterImpl(ActorSystem system, String host, String seedHost) throws RemoteException {
super();
this.system = (AbsActorSystem) system;
this.members = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
this.seed = seedHost;
if (!host.equals(seedHost))
this.uuid = host + "/" + UUID.randomUUID().toString().replaceAll("-", "");
else this.uuid = host + "/master";
try {
Naming.bind("rmi://" + this.uuid, this);
join(this.uuid);
if (!host.equals(seedHost))
updateMembers(seedHost, this.uuid);
} catch (AlreadyBoundException | MalformedURLException e) {
e.printStackTrace();
}
}
示例7: actorOf
import java.rmi.Naming; //导入依赖的package包/类
/**
* Create an instance of {@code actor} returning a {@link ActorRef reference}
* to it using the given {@code mode} and a unique name inside the cluster.
*
* @param actor The type of actor that has to be created
* @param mode The mode of the actor requested
* @param name The name of the actor inside the cluster, must be unique
*
* @return A reference to the actor
*/
@Override
public ActorRef<? extends Message> actorOf(Class<? extends Actor> actor, ActorMode mode, String name) throws RemoteException {
ActorRef<? extends Message> ref = null;
switch (mode) {
case LOCAL:
ref = system.actorOf(actor, mode, name);
synchronized(this) {
updateRemoteActors(name, ref);
}
break;
case REMOTE:
String addr = name.split("/")[0];
String memberName = (String)
members.stream().filter(x -> x.startsWith(addr)).toArray()[0];
try {
Cluster remoteMember = (Cluster) Naming.lookup("rmi://" + memberName);
ref = remoteMember.actorOf(actor, ActorMode.LOCAL, name);
} catch (NotBoundException | MalformedURLException | RemoteException e) {
e.printStackTrace();
}
break;
}
return ref;
}
示例8: updateRemoteActors
import java.rmi.Naming; //导入依赖的package包/类
/**
* Update new members' remote actors map so they can access to the actors
* located on other {@code ActorSystem}.
*
* @param newMember The identifier name of the new member, in order to be
* located across the cluster and be updated with remote actors table.
*/
@Override
public void updateRemoteActors(String newMember) throws RemoteException {
system.getRemoteActors()
.entrySet()
.stream()
.forEach(x -> {
try {
final Cluster cluster =
(Cluster) Naming.lookup("rmi://" + newMember);
cluster.addRemoteRef(x.getKey(), x.getValue());
} catch (RemoteException | MalformedURLException | NotBoundException e) {
e. printStackTrace();
}
});
}
示例9: stop
import java.rmi.Naming; //导入依赖的package包/类
/**
* Stops {@code actor} inside the cluster.
*
* @param actor The actor to be stopped
*/
@Override
public synchronized void stop(ActorRef<? extends Message> actorRef) throws RemoteException {
AbsActorSystem abSystem = (AbsActorSystem) system;
if (!abSystem.contains(actorRef)) {
String destName = actorRef.getName();
if (abSystem.containsRemote(destName)) {
try {
String addr = destName.split("/")[0];
String memberName = (String)
members.stream().filter(x -> x.startsWith(addr)).toArray()[0];
Cluster clusterMember = (Cluster) Naming.lookup("rmi://" + memberName);
clusterMember.stop(actorRef);
} catch (NotBoundException | MalformedURLException e) {
e.printStackTrace();
}
} else throw new NoSuchActorException();
} else {
system.stop(actorRef);
}
}
示例10: main
import java.rmi.Naming; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
try {
int namingPort = Integer.getInteger(DUnitLauncher.RMI_PORT_PARAM).intValue();
int vmNum = Integer.getInteger(DUnitLauncher.VM_NUM_PARAM).intValue();
LogWriter log = Log.createLogWriter("dunit-vm-" + vmNum, DUnitLauncher.LOG_LEVEL);
System.out.println("VM" + vmNum + " is launching");
DUnitLauncher.initSystemProperties(log);
MasterRemote holder = (MasterRemote) Naming.lookup("//localhost:" + namingPort + "/" + DUnitLauncher.MASTER_PARAM);
RemoteTestModule.Master = new FakeMaster();
DUnitLauncher.locatorPort = holder.getLocatorPort();
Naming.bind("//localhost:" + namingPort + "/vm" + vmNum, new FakeRemoteTestModule(log));
holder.signalVMReady();
//This loop is here so this VM will die even if the master is mean killed.
while(true) {
holder.ping();
Thread.sleep(1000);
}
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
}
示例11: getPi2GoLiteLocat
import java.rmi.Naming; //导入依赖的package包/类
public final synchronized static Pi2GoLite getPi2GoLiteLocat(String rmiServerUrl)
throws NotBoundException,
MalformedURLException,
RemoteException
{
// Assign security manager
if (System.getSecurityManager() == null)
{
System.setSecurityManager
(new SecurityManager());
}
// Call registry for PowerService
Pi2GoLiteRemote piRemote = (Pi2GoLiteRemote) Naming.lookup
("rmi://" + rmiServerUrl + "/Pi2GoLiteRemoteImpl");
//("rmi://" +"raspi-pi2go.homenet.telecomitalia.it" + "/Pi2GoLiteRemote");
Pi2GoLite piLocal = new Pi2GoLiteLocal (piRemote);
return piLocal;
}
示例12: create
import java.rmi.Naming; //导入依赖的package包/类
public static String create(final Service svc, final int port) {
String svcUri = null;
try {
synchronized(SVC_MAP) {
//ensureRmiUseFixedPort(port);
ensureRmiRegistryIsAvailableAt(port);
UnicastRemoteObject.exportObject(svc, port);
final String svcName = svc.getName();
svcUri = getLocalSvcUri(svcName, port).toString();
if(!SVC_MAP.containsKey(svcName + ":" + port)) {
Naming.rebind(svcUri, svc);
SVC_MAP.put(svcName + ":" + port, svc);
} else {
throw new AssertionError("Service already registered");
}
}
} catch(final IOException | URISyntaxException e) {
e.printStackTrace(System.err);
}
return svcUri;
}
示例13: close
import java.rmi.Naming; //导入依赖的package包/类
public static String close(final Service svc)
throws RemoteException, MalformedURLException {
final String svcName = svc.getName();
String svcUri = null;
try {
UnicastRemoteObject.unexportObject(svc, true);
} finally {
try {
svcUri = getLocalSvcUri(svcName, svc.getRegistryPort()).toString();
Naming.unbind(svcUri);
synchronized(SVC_MAP) {
if(null == SVC_MAP.remove(svcName + ":" + svc.getRegistryPort())) {
System.err.println(
"Failed to remove the service \"" + svcName + "\""
);
}
}
} catch(final NotBoundException | URISyntaxException e) {
e.printStackTrace(System.err);
}
}
return svcUri;
}
示例14: main
import java.rmi.Naming; //导入依赖的package包/类
public static void main(String[] args) {
String location [] = {
"rmi://127.0.0.1/seattle.mig.com/gumballmachine"
};
GumballMonitor [] monitors = new GumballMonitor[location.length];
for(int i = 0 ; i < location.length ; i ++){
try{
GumballMachineRemote remote = (GumballMachineRemote) Naming.lookup(location[i]);
monitors[i] = new GumballMonitor(remote);
System.out.println(monitors[i]);
}catch(Exception e){
e.printStackTrace();
}
}
for(int i = 0 ; i < location.length ; i ++){
monitors[i].report();
}
}
示例15: main
import java.rmi.Naming; //导入依赖的package包/类
public static void main(String[] args) {
GumballMachineRemote remote = null;
int count = 0;
if(args.length < 2){
System.out.println("GumballMachine <name> <inventory>");
System.exit(1);
}
count = Integer.parseInt(args[1]);
try {
remote = new GumballMachine(args[0], count);
System.out.println("/"+args[0]+"/gumballmachine");
Naming.rebind("/"+args[0]+"/gumballmachine", remote);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}