📄 rmiimtpmanager.java
字号:
public void reconnected(PlatformManager pm) {
// Just do nothing
}
public Service.Slice createSliceProxy(String serviceName, Class itf, Node where) throws IMTPException {
try {
Class proxyClass = Class.forName(serviceName + "Proxy");
Service.Slice proxy = (Service.Slice) proxyClass.newInstance();
if (proxy instanceof SliceProxy) {
((SliceProxy) proxy).setNode(where);
}
else if (proxy instanceof Service.SliceProxy) {
((Service.SliceProxy) proxy).setNode(where);
}
else {
throw new IMTPException("Class "+proxyClass.getName()+" is not a slice proxy.");
}
return proxy;
}
catch(Exception e) {
throw new IMTPException("Error creating a slice proxy", e);
}
}
public Node getLocalNode() throws IMTPException {
return localNode;
}
/**
*/
public void shutDown() {
try {
if (localNode != null) {
localNode.exit();
}
}
catch (IMTPException imtpe) {
// Should never happen since this is a local call
imtpe.printStackTrace();
}
}
/**
*/
public List getLocalAddresses() throws IMTPException {
try {
List l = new LinkedList();
// The port is meaningful only on the Main container
TransportAddress addr = new RMIAddress(InetAddress.getLocalHost().getHostName(), String.valueOf(localPort), null, null);
l.add(addr);
return l;
}
catch (Exception e) {
throw new IMTPException("Exception in reading local addresses", e);
}
}
public boolean compareAddresses(String addr1, String addr2) throws IMTPException {
return addr1.equalsIgnoreCase(addr2);
}
/**
Creates the client socket factory, which will be used
to instantiate a <code>UnicastRemoteObject</code>.
@return The client socket factory.
*/
public RMIClientSocketFactory getClientSocketFactory() {
return null;
}
/**
Creates the server socket factory, which will be used
to instantiate a <code>UnicastRemoteObject</code>.
@return The server socket factory.
*/
public RMIServerSocketFactory getServerSocketFactory() {
return null;
}
private static final char SLASH = '/';
private static final char COLON = ':';
private static final char DIESIS = '#';
public TransportAddress stringToAddr(String url) throws IMTPException {
// FIXME: Refactor this code with jade.imtp.leap.TrasportProtocol.parseURL()
if (url == null) {
throw new IMTPException("Null URL");
}
String protocol = null;
String host = null;
String port = null;
String file = null;
String anchor = null;
int fieldStart = 0;
int fieldEnd;
// Protocol
fieldEnd = url.indexOf(COLON, fieldStart);
if (fieldEnd > 0 && url.charAt(fieldEnd+1) == SLASH && url.charAt(fieldEnd+2) == SLASH) {
protocol = url.substring(fieldStart, fieldEnd);
}
else {
throw new IMTPException("Invalid URL: "+url+".");
}
fieldStart = fieldEnd+3;
// Host
fieldEnd = url.indexOf(COLON, fieldStart);
if (fieldEnd > 0) {
// A port is specified after the host
host = url.substring(fieldStart, fieldEnd);
fieldStart = fieldEnd+1;
// Port
fieldEnd = url.indexOf(SLASH, fieldStart);
if (fieldEnd > 0) {
// A file is specified after the port
port = url.substring(fieldStart, fieldEnd);
fieldStart = fieldEnd+1;
// File
fieldEnd = url.indexOf(DIESIS, fieldStart);
if (fieldEnd > 0) {
// An anchor is specified after the file
file = url.substring(fieldStart, fieldEnd);
fieldStart = fieldEnd+1;
// Anchor
anchor = url.substring(fieldStart, url.length());
}
else {
// No anchor is specified after the file
file = url.substring(fieldStart, url.length());
}
}
else {
// No file is specified after the port
port = url.substring(fieldStart, url.length());
}
}
else {
// No port is specified after the host
fieldEnd = url.indexOf(SLASH, fieldStart);
if (fieldEnd > 0) {
// A file is specified after the host
host = url.substring(fieldStart, fieldEnd);
fieldStart = fieldEnd+1;
// File
fieldEnd = url.indexOf(DIESIS, fieldStart);
if (fieldEnd > 0) {
// An anchor is specified after the file
file = url.substring(fieldStart, fieldEnd);
fieldStart = fieldEnd+1;
// Anchor
anchor = url.substring(fieldStart, url.length());
}
else {
// No anchor is specified after the file
file = url.substring(fieldStart, url.length());
}
}
else {
// No file is specified after the host
host = url.substring(fieldStart, url.length());
}
}
return new RMIAddress(host, port, file, anchor);
}
/**
Inner class PlatformManagerAdapter.
An adapter, implementing the PlatformManager interface, to
a ServiceManagerRMI stub
*/
private class PlatformManagerAdapter implements PlatformManager {
private String localAddress;
private ServiceManagerRMI adaptee;
private PlatformManagerAdapter(ServiceManagerRMI adaptee, String localAddress) {
this.localAddress = localAddress;
this.adaptee = adaptee;
}
public String getPlatformName() throws IMTPException {
try {
return adaptee.getPlatformName();
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public String getLocalAddress() {
return localAddress;
}
public void setLocalAddress(String addr) {
// Should never be called
}
public String addNode(NodeDescriptor dsc, Vector nodeServices, boolean propagated) throws IMTPException, ServiceException, JADESecurityException {
try {
return adaptee.addNode(dsc, nodeServices, propagated);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public void removeNode(NodeDescriptor dsc, boolean propagated) throws IMTPException, ServiceException {
try {
adaptee.removeNode(dsc, propagated);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public void addSlice(ServiceDescriptor service, NodeDescriptor dsc, boolean propagated) throws IMTPException, ServiceException {
try {
adaptee.addSlice(service, dsc, propagated);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public void removeSlice(String serviceKey, String sliceKey, boolean propagated) throws IMTPException, ServiceException {
try {
adaptee.removeSlice(serviceKey, sliceKey, propagated);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public void addReplica(String newAddr, boolean propagated) throws IMTPException, ServiceException {
try {
adaptee.addReplica(newAddr, propagated);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public void removeReplica(String address, boolean propagated) throws IMTPException, ServiceException {
try {
adaptee.removeReplica(address, propagated);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public Service.Slice findSlice(String serviceKey, String sliceKey) throws IMTPException, ServiceException {
try {
return adaptee.findSlice(serviceKey, sliceKey);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public Vector findAllSlices(String serviceKey) throws IMTPException, ServiceException {
try {
return adaptee.findAllSlices(serviceKey);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public void adopt(Node n, Node[] children) throws IMTPException {
try {
adaptee.adopt(n, children);
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public void ping() throws IMTPException {
try {
adaptee.ping();
}
catch(RemoteException re) {
throw new IMTPException("RMI exception", re);
}
}
public String toString() {
return "PlatformManagerAdapter: local-address="+localAddress+" adaptee="+adaptee;
}
} // END of inner class PlatformManagerAdapter
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -