package Framework;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
import Framework.anchored.AnchoredProxy;
import Framework.anchored.MethodMapper;
import Framework.anchored.ServiceInvoker;
import Framework.anchored.ServiceProxy;
public class FileSystemProxy extends FileSystem implements AnchoredProxy, RemoteProxy{
private transient ServiceProxy proxy = null;
private String objectName;
private String hostName;
private int port;
/**
* @deprecated This constructor is present only to allow proxies to be serialised via the efficient serialiser
* and should not be called at any other time.
*/
public FileSystemProxy() {
super((ServiceObjectContext)null);
}
/**
* This constructor can store no reference to the original object,
* but must instead copy over it's necessary attributes.
*/
public FileSystemProxy(FileSystem baseClass) {
super((ServiceObjectContext)null);
ServiceInvoker serviceInvoker = getInvoker(baseClass);
if (serviceInvoker == null) {
throw new UsageException("Cannot create a proxy for an object that has not yet been exported.");
}
this.objectName = serviceInvoker.getObjectName();
// The proxy is being created on the same host as the real object
//this.hostName = System.getProperty("RMIregistry.host");
try {
this.hostName = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new UsageException("Cannot BIND to RMI object ", e);
}
this.port = serviceInvoker.getPort();
}
private ServiceProxy getServiceProxy() {
if (proxy == null) {
proxy = new ServiceProxy(objectName, hostName, port, this.getClass().getSuperclass());
}
return proxy;
}
@Override
public TextData getCurrentDir() {
String qq_name = MethodMapper.computeName("getCurrentDir");
return (TextData)getServiceProxy().intercept(qq_name);
}
@Override
public TextData getCurrentRemoteDir() {
String qq_name = MethodMapper.computeName("getCurrentRemoteDir");
return (TextData)getServiceProxy().intercept(qq_name);
}
@Override
public void pullFiles(Array_Of_TextData<TextData> copyList, int cmdFlags) {
String qq_name = MethodMapper.computeName("pullFiles", Array_Of_TextData.class, Integer.class);
getServiceProxy().intercept(qq_name, copyList, cmdFlags);
}
@Override
public void pushFiles(Array_Of_TextData<TextData> copyList, int cmdFlags) {
String qq_name = MethodMapper.computeName("pushFiles", Array_Of_TextData.class, Integer.class);
getServiceProxy().intercept(qq_name, copyList, cmdFlags);
}
@Override
public void setRemoteDir(String dirName) {
String qq_name = MethodMapper.computeName("setRemoteDir", String.class);
getServiceProxy().intercept(qq_name, dirName);
}
@Override
public void setRemoteDir(TextData dirName) {
String qq_name = MethodMapper.computeName("setRemoteDir", TextData.class);
getServiceProxy().intercept(qq_name, dirName);
}
@Override
public void setRemoteDir(TextData dirName, boolean collapseDir) {
String qq_name = MethodMapper.computeName("setRemoteDir", TextData.class, Boolean.class);
getServiceProxy().intercept(qq_name, dirName, collapseDir);
}
@Override
public void setLocalDir(String dirName) {
String qq_name = MethodMapper.computeName("setLocalDir", String.class);
getServiceProxy().intercept(qq_name, dirName);
}
@Override
public void setLocalDir(TextData dirName) {
String qq_name = MethodMapper.computeName("setLocalDir", TextData.class);
getServiceProxy().intercept(qq_name, dirName);
}
@Override
public void setLocalDir(TextData dirName, boolean collapseDir) {
String qq_name = MethodMapper.computeName("setLocalDir", TextData.class, Boolean.class);
getServiceProxy().intercept(qq_name, dirName, collapseDir);
}
@Override
public void setRemoteFS(FileSystem remoteFS) {
String qq_name = MethodMapper.computeName("setRemoteFS", FileSystem.class);
getServiceProxy().intercept(qq_name, remoteFS);
}
/**
* Satisfy the {@link RemoteEventProxy} interface
*/
@Override
public String registerInterest(String pHostName, RemoteEvent pAnchoredObject, String pEvent) {
String qq_name = MethodMapper.computeName("registerInterest", String.class, RemoteEvent.class, String.class);
return (String)getServiceProxy().intercept(qq_name, pHostName, pAnchoredObject, pEvent);
}
@Override
public void postEvent(String pEventName, Hashtable<String, Object> pParameters) {
String qq_name = MethodMapper.computeName("postEvent", String.class, Hashtable.class);
getServiceProxy().intercept(qq_name, pEventName, pParameters);
}
@Override
public void deregisterInterest(String pHostName, RemoteEvent pAnchoredObject, String pEvent) {
String qq_name = MethodMapper.computeName("deregisterInterest", String.class, RemoteEvent.class, String.class);
getServiceProxy().intercept(qq_name, pHostName, pAnchoredObject, pEvent);
}
}