diff --git a/SAS/OTB/jOTDB2/src/nl/astron/lofar/sas/otb/jotdb2/jOTDBserver.java b/SAS/OTB/jOTDB2/src/nl/astron/lofar/sas/otb/jotdb2/jOTDBserver.java index 16f01637e1d5b18c434c97442ca0ae4a724ce075..be2913170dc8b129f670c8c3c0e4473ef3268d20 100644 --- a/SAS/OTB/jOTDB2/src/nl/astron/lofar/sas/otb/jotdb2/jOTDBserver.java +++ b/SAS/OTB/jOTDB2/src/nl/astron/lofar/sas/otb/jotdb2/jOTDBserver.java @@ -22,6 +22,8 @@ package nl.astron.lofar.sas.otb.jotdb2; import java.rmi.registry.*; import java.rmi.server.RMISocketFactory; +import nl.astron.lofar.lofarutils.remoteFileAdapter; +import nl.astron.lofar.lofarutils.remoteFileInterface; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; @@ -36,6 +38,7 @@ public class jOTDBserver { private static jTreeValueAdapter jTreeValueAdapter; private static jConverter jConverterAdaptee; private static jConverterAdapter jConverterAdapter; + private static remoteFileAdapter remoteFileAdapter; static { @@ -141,6 +144,23 @@ public class jOTDBserver { localRegistry.rebind(jConverterInterface.SERVICENAME, jConverterAdapter); logger.info("Published jConverterInterface as service " + jConverterInterface.SERVICENAME + ". Ready..."); + + // Export remoteFile + remoteFileAdapter = new remoteFileAdapter(remoteFileInterface.SERVICENAME); + //A custom port was specified, export the object using the port specified + if(objectPort!=0){ + remoteFileAdapter.unexportObject(remoteFileAdapter,true); + remoteFileAdapter.exportObject(remoteFileAdapter,objectPort); + } + logger.info("jOTDBserver publishing service " + remoteFileInterface.SERVICENAME + " in local registry..."); + localRegistry.rebind(remoteFileInterface.SERVICENAME, remoteFileAdapter); + + logger.info("Published remoteFileInterface as service " + remoteFileInterface.SERVICENAME + ". Ready..."); + + + + + String statusmessage = "jOTDBserver is ready for incoming calls"; if (args.length > 4) { Integer rmiPort = new Integer(args[4]); diff --git a/SAS/OTB/jOTDB2/test/tRemoteFile.java b/SAS/OTB/jOTDB2/test/tRemoteFile.java new file mode 100644 index 0000000000000000000000000000000000000000..50d4136bc55be15bad19efb2a3df96b25eb0d0ce --- /dev/null +++ b/SAS/OTB/jOTDB2/test/tRemoteFile.java @@ -0,0 +1,61 @@ + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.rmi.Naming; +import nl.astron.lofar.lofarutils.remoteFileInterface; + + +public class tRemoteFile { + + + public static String RMIRegistryName = remoteFileInterface.SERVICENAME; + + public static void main(String[] argv) { + if(argv.length != 3) { + System.out.println("Usage: java tRemoteFile fileName machineName machinePort"); + System.out.println("Where file is a file on the client."); + System.exit(0); + } + String aRF="rmi://"+argv[1]+":"+argv[2]+"/"+RMIRegistryName; + + try { + // do the test + System.out.println("Starting..."); + remoteFileInterface fi = (remoteFileInterface) Naming.lookup(aRF); + + System.out.println("Starting upload"); + File aFile = new File(argv[0]); + byte uldata[] = new byte[(int)aFile.length()]; + System.out.println("File opened: "+aFile.getName()+" bytesize: "+ uldata.length); + BufferedInputStream input = new BufferedInputStream(new FileInputStream(aFile)); + input.read(uldata,0,uldata.length); + input.close(); + if (fi.uploadFile(uldata,argv[0]+".uploaded")) { + System.out.println("upload finished"); + } else { + System.out.println("upload failed"); + } + + + System.out.println("Starting download"); + byte[] dldata = fi.downloadFile(argv[0]+".uploaded"); + File file = new File(argv[0]+".downloaded"); + System.out.println("opening File: "+file.getName()); + BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file.getName())); + System.out.println("Received buffer length: "+dldata.length); + output.write(dldata,0,dldata.length); + output.flush(); + output.close(); + System.out.println("Download finished"); + } catch(Exception e) { + System.err.println("FileServer exception: "+ e.getMessage()); + e.printStackTrace(); + } + } +} + + +