generating IL file OK
authorAleš Křenek <ljocha@ics.muni.cz>
Mon, 14 Sep 2009 13:53:54 +0000 (13:53 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Mon, 14 Sep 2009 13:53:54 +0000 (13:53 +0000)
org.glite.lb.client-java/examples/CreamTest.java
org.glite.lb.client-java/src/org/glite/lb/Context.java
org.glite.lb.client-java/src/org/glite/lb/ContextDirect.java
org.glite.lb.client-java/src/org/glite/lb/ContextIL.java
org.glite.lb.client-java/src/org/glite/lb/Escape.java

index e4148a3..8819101 100644 (file)
@@ -6,8 +6,18 @@ public class CreamTest {
 public static void main(String[] args)
 {
 
+   int i;
+   String srv = null,socket = null,prefix = null,lib = null;
+
+   for (i = 0; i < args.length; i++) {
+       if (args[i].equals("-m")) srv = args[++i];
+       else if (args[i].equals("-s")) socket = args[++i];
+       else if (args[i].equals("-f")) prefix = args[++i];
+       else if (args[i].equals("-l")) lib = args[++i];
+   }
+
    try {
-       String[] srvpart = args[0].split(":");
+       String[] srvpart = srv.split(":");
        int srvport = Integer.parseInt(srvpart[1]);
        Jobid   job = new Jobid(srvpart[0],srvport);
 
@@ -28,14 +38,14 @@ public static void main(String[] args)
 
        System.out.println("JOBID="+job);
 
+       ContextIL       ctx = new ContextIL(prefix,socket,lib);
+       ctx.setSource(Sources.EDG_WLL_SOURCE_CREAM_CORE);
+       ctx.setJobid(job);
+       ctx.setSeqCode(new SeqCode(SeqCode.CREAM,"no_seqcodes_with_cream"));
+       ctx.setUser(ctxd.getUser());
 
-
-/*
-       reg.setJdl
-
-
-       ContextIL       ctx = new ContextIL();
-*/
+       reg.setJdl("[\n\ttest = \"hellow, world\";\n]");
+       ctx.log(reg);
        
 
    } catch (Exception e)
index 8449a66..87af110 100644 (file)
@@ -13,7 +13,6 @@ import org.glite.jobid.Jobid;
  */
 public abstract class Context {
 
-    private int id;
     private int source;
     private int flag;
     private String host;
@@ -44,17 +43,13 @@ public abstract class Context {
      *  or flag < 0 or source <=0 || >= 9 
      * 
      */
-    public Context(int id,
-            int source,
+    public Context(int source,
             int flag,
             String host,
             String user,
             String prog,
             String srcInstance,
             Jobid jobid) {
-        if (id < 0) {
-            id = new Random().nextInt();
-        }
 
         if (source <= -1 || source > Sources.EDG_WLL_SOURCE_LB_SERVER) {
             throw new IllegalArgumentException("Context source");
@@ -88,7 +83,6 @@ public abstract class Context {
             throw new IllegalArgumentException("Context jobid");
         }
 
-        this.id = id;
         this.source = source;
         this.flag = flag;
         this.host = host;
@@ -211,8 +205,7 @@ public abstract class Context {
 
         if (seqCode != null) seqCode.incrementSeqCode(source);
 
-        output = ("DG.LLLID=" + id +
-                " DG.USER=\"" + Escape.ulm(user) + "\"" +
+        output = (" DG.USER=\"" + Escape.ulm(user) + "\"" +
                 " DATE=" + date +
                 " HOST=\"" + Escape.ulm(host) + "\"" +
                 " PROG=" + Escape.ulm(prog) +
@@ -274,28 +267,6 @@ public abstract class Context {
     }
 
     /**
-     * Gets message id.
-     * 
-     * @return message id
-     */
-    public int getId() {
-        return id;
-    }
-
-    /**
-     * Sets message id.
-     * 
-     * @param id message id
-     * @throws java.lang.IllegalArgumentException if id is lower than 0
-     */
-    public void setId(int id) {
-        if (id < 0) {
-            throw new IllegalArgumentException("Context id");
-        }
-        this.id = id;
-    }
-
-    /**
      * Gets jobid.
      * 
      * @return jobid
index eea8361..5f4e91a 100644 (file)
@@ -39,7 +39,6 @@ public class ContextDirect extends Context
                        ssl.setCredentials(cred);
                        Socket sock = ssl.connect(server,port+1,timeout);
                        setUser(ssl.myDN());
-System.out.println("setUser("+ssl.myDN()+")");
                        try { il = new ILProto(sock); }
                        catch (Throwable e) { throw new LBException(e); }
                }
index 2d798cb..aca0fad 100644 (file)
@@ -9,13 +9,11 @@ import org.glite.jobid.Jobid;
  */
 public class ContextIL extends Context {
 
-    private String pathToSocket;
-    private String pathToNativeLib;
+    private String socket;
     private String prefix;
     private int repeatWriteToFile = 5;
     private int connAttempts = 3;
     private int timeout = 3;
-    private Boolean useUnixSocket = Boolean.TRUE;
 
     //tutorial http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
     //native method which is written in C and imported to Java
@@ -32,88 +30,23 @@ public class ContextIL extends Context {
     public ContextIL() {
     }
 
-    /**
-     * Creates new instance of ContextIL.
-     * 
-     * @param pathToSocket path to unix socket
-     * @param prefix path where are stored messages
-     */
-    public ContextIL(String pathToSocket, String prefix) {
+    public ContextIL(String prefix) {
         this.prefix = prefix;
-        this.pathToSocket = pathToSocket;
     }
 
-    /**
-     * Creates new instance of ContextIL.
-     * 
-     * @param id message id, if null, random number is generated
-     * @param source one if paramaters of Sources enumeration
-     * @param flag
-     * @param host host name, if null or "", the name is get from host name of this computer
-     * @param user user name
-     * @param prog if null then is used "egd-wms"
-     * @param srcInstance if null then it is set as ""
-     * @param jobid jobid
-     * @param path path to unix socket
-     * @param prefix path where are stored messages
-     * @throws java.lang.IllegalArgumentException if source, user, jobid, prefix 
-     * or path is null or flag < 0
-     */
-    public ContextIL(int id,
-            int source,
-            int flag,
-            String host,
-            String user,
-            String prog,
-            String srcInstance,
-            Jobid jobid,
-            String pathToSocket,
-            String prefix) {
-
-        super(id, source, flag, host, user, prog, srcInstance, jobid);
-
-        if (prefix == null) {
-            throw new IllegalArgumentException("ContextIL prefix");
-        }
+    public ContextIL(String prefix,String socket,String lib)
+    {
+       if (prefix == null) throw new IllegalArgumentException("ContextIL prefix");
+       if ((socket != null && lib == null) || (socket == null && lib != null))
+               throw new IllegalArgumentException("ContextIL both socket and lib must be set");
 
-        if (pathToSocket == null) {
-            throw new IllegalArgumentException("ContextIL path");
-        }
+       this.prefix = prefix;
+       this.socket = socket;
 
-        this.prefix = prefix;
-        this.pathToSocket = pathToSocket;
+       if (lib != null) System.loadLibrary(lib);
     }
 
-    /**
-     * Writes file position and message to specified socket.
-     * 
-     * @param pathToSocket path to unix socket
-     * @param fileSize size of the file before new message was written there
-     * @param message message which will be send
-     * @param conn_attempts count of connection attempts
-     * @param time_out connection timeout
-     */
-    private void writeToSocket(String pathToSocket,
-            long fileSize,
-            String message) {
-
-        if (useUnixSocket.booleanValue()) {
-            try {
-                System.loadLibrary("glite_lb_sendviasocket");
-               message += '\n';
-                   sendToSocket(pathToSocket,
-                        fileSize,
-                        message,
-                        message.length(),
-                        connAttempts,
-                        timeout);
-                
-            } catch (UnsatisfiedLinkError ex) {
-                useUnixSocket = Boolean.FALSE;
-                System.err.println(ex);
-            }
-        }
-    }
+       
 
     /**
      * Writes event message to the file and socket.
@@ -130,90 +63,20 @@ public class ContextIL extends Context {
             throw new IllegalArgumentException("ContextIL prefix");
         }
 
-        if (pathToSocket == null || pathToSocket.equals("")) { 
-            pathToSocket = new String("");
-            useUnixSocket = Boolean.FALSE;
-        }
-
-        if (pathToNativeLib == null || pathToNativeLib.equals("")) { 
-            pathToNativeLib = new String("");
-            useUnixSocket = Boolean.FALSE;
-        }
-        
-        String message = super.createMessage(event);
-
-        Long fileLength = ILFileWriter.write(prefix, message, repeatWriteToFile);
-
-        writeToSocket(pathToSocket, fileLength.longValue(), message);
-    }
-
-    /**
-     * Gets path to socket.
-     * 
-     * @return pathToSocket to socket
-     */
-    public String getPathToSocket() {
-        return pathToSocket;
-    }
-
-    /**
-     * Sets path to socket.
-     * 
-     * @param pathToSocket path to socket
-     * @throws java.lang.IllegalArgumentException if path is null
-     */
-    public void setPathToSocket(String pathToSocket) {
-        if (pathToSocket == null) {
-            throw new IllegalArgumentException("ContextIL pathToSocket");
-        }
-
-        this.pathToSocket = pathToSocket;
-    }
+        String message = "DG.LLLID=\"0\"" + super.createMessage(event);
 
-    /**
-     * Gets path to nativelib file which is needed to send messages via unix socket
-     * 
-     * @return pathToNativeLib to native library (libnativelib.so)
-     */
-    public String getPathToNativeLib() {
-        return pathToNativeLib;
-    }
+       String file = prefix + "." + getJobid().getUnique();
 
-    /**
-     * Sets path to nativelib file which is needed to send messages via unix socket
-     * @param pathToNativeLib path to shared library (libnativelib.so)
-     */
-    public void setPathToNativeLib(String pathToNativeLib) {
-        if (pathToNativeLib == null) {
-            throw new IllegalArgumentException("ContextIL pathToNativeLib");
-        }
+        Long fileLength = ILFileWriter.write(file, message, repeatWriteToFile);
 
-        this.pathToNativeLib = pathToNativeLib;
+       if (socket != null) sendToSocket(socket,fileLength.longValue(),message,message.length(),connAttempts,timeout);
     }
 
-    /**
-     * Gets path where are stored messages.
-     * 
-     * @return path where are stored messages
-     */
     public String getPrefix() {
         return prefix;
     }
 
     /**
-     * Sets path where are stored messages.
-     * 
-     * @param prefix path where are stored messages
-     */
-    public void setPrefix(String prefix) {
-        if (prefix == null) {
-            throw new IllegalArgumentException("ContextIL prefix");
-        }
-
-        this.prefix = prefix;
-    }
-
-    /**
      * Gets count of repeated write to file if some exception is thrown.
      * 
      * @return count of repeated write to file
@@ -279,15 +142,4 @@ public class ContextIL extends Context {
         this.timeout = timeout;
     }
 
-    public Boolean getUseUnixSocket() {
-        return useUnixSocket;
-    }
-
-    public void setUseUnixSocket(Boolean useUnixSocket) {
-        if (useUnixSocket == null) {
-            throw new IllegalArgumentException("ContextIL useUnixSocket");
-        }
-
-        this.useUnixSocket = useUnixSocket;
-    }
 }
index 0846662..a477629 100644 (file)
@@ -2,8 +2,8 @@ package org.glite.lb;
 
 class Escape {
        public static String ulm(String in) {
-               String out = in.replaceAll("\"", "\\\"");
-               out = out.replaceAll("\n", "\\\n");
+               String out = in.replaceAll("\"", "\\\\\"");
+               out = out.replaceAll("\n", "\\\\\\n");
                return out;
        }
 }