You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2011/05/14 20:35:02 UTC

svn commit: r1103180 [22/23] - in /incubator/airavata/donations/ogce-donation: ./ modules/ modules/utils/ modules/utils/schemas/ modules/utils/schemas/gfac-schema-utils/ modules/utils/schemas/gfac-schema-utils/generated/ modules/utils/schemas/gfac-sche...

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/MsgBoxServiceSkeleton.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/MsgBoxServiceSkeleton.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/MsgBoxServiceSkeleton.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/MsgBoxServiceSkeleton.java Sat May 14 18:34:50 2011
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox;
+
+import java.io.StringReader;
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.service.Lifecycle;
+import org.apache.log4j.Logger;
+
+import edu.indiana.extreme.www.xgws.msgbox.Storage.MsgBoxStorage;
+import edu.indiana.extreme.www.xgws.msgbox.Storage.memory.InMemoryImpl;
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxNameSpConsts;
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxUtils;
+
+// Referenced classes of package edu.indiana.extreme.www.xgws.msgbox._2004:
+//            ProcessingContext
+
+public class MsgBoxServiceSkeleton
+    implements Lifecycle
+{
+
+    public MsgBoxServiceSkeleton()
+    {
+        dbImplenented = true;
+    }
+
+    public void init(ServiceContext servicecontext)
+        throws AxisFault
+    {
+    }
+
+    public static void setStorage(MsgBoxStorage storageIn)
+    {
+        storage = storageIn;
+    }
+
+    public void destroy(ServiceContext serviceContext)
+    {
+        if(logger.isDebugEnabled())
+            logger.debug("Stopping Service....");
+        if(!dbImplenented)
+            setMap2();
+    }
+
+    public OMElement createMsgBox()
+        throws Exception
+    {
+        OMElement dd = factory.createOMElement(ProcessingContext.CREATE_MSGBOX_RESP_QNAME);
+        String createdMsgBoxId = "";
+        OMNamespace omNs = factory.createOMNamespace("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "ns1");
+        OMElement url = factory.createOMElement("msgboxid", omNs);
+        try
+        {
+            createdMsgBoxId = storage.createMsgBox();
+        }
+        catch(Exception e)
+        {
+            logger.fatal((new StringBuilder()).append("Error creating the message box ").append(createdMsgBoxId).toString(), e);
+            AxisFault f = new AxisFault((new StringBuilder()).append("Error creating the message box ").append(createdMsgBoxId).toString(), e);
+            f.setFaultCode("6000");
+            throw f;
+        }
+        url.setText(createdMsgBoxId);
+        dd.addChild(url);
+        return dd;
+    }
+
+    String getRandom(int length)
+    {
+        UUID uuid = UUID.randomUUID();
+        String myRandom = uuid.toString();
+        return myRandom.substring(1, length);
+    }
+
+    public OMElement storeMessages(ProcessingContext procCtxt)
+        throws Exception
+    {
+        String clientid = "";
+        OMElement message = procCtxt.getMessage();
+        OMElement status = factory.createOMElement(new QName((new StringBuilder()).append(MsgBoxNameSpConsts.MSG_BOX.getNamespaceURI()).append("/").toString(), "status", "msg"));
+        if(procCtxt.getMsgBoxAddr() != null)
+            clientid = procCtxt.getMsgBoxAddr();
+        try
+        {
+            storage.putMessageIntoMsgBox(clientid, procCtxt.getMessageId(), procCtxt.soapAction, message);
+            status.setText("true");
+        }
+        catch(SQLException e)
+        {
+            logger.fatal((new StringBuilder()).append("Exception thrown while storing message: ").append(message).append("in msgbx: ").append(clientid).toString(), e);
+            status.setText("false");
+        }
+        OMElement resp = factory.createOMElement(ProcessingContext.STOREMSG_RESP_QNAME);
+        resp.addChild(status);
+        resp.declareNamespace(MsgBoxNameSpConsts.MSG_BOX);
+        return resp;
+    }
+
+    public OMElement takeMessages(ProcessingContext procCtxt)
+        throws Exception
+    {
+        String key = "";
+        if(procCtxt.getMsgBoxAddr() != null)
+            key = procCtxt.getMsgBoxAddr();
+        OMElement respEl = factory.createOMElement(new QName((new StringBuilder()).append(MsgBoxNameSpConsts.MSG_BOX.getNamespaceURI()).append("/").toString(), "takeMessagesResponse", "msg"));
+        OMElement messageSet = factory.createOMElement(new QName((new StringBuilder()).append(MsgBoxNameSpConsts.MSG_BOX.getNamespaceURI()).append("/").toString(), "messages", "msg"));
+        try
+        {
+        	LinkedList<String> list = (LinkedList<String>) storage.takeMessagesFromMsgBox(key);
+            int i = 0;
+            if(list != null)
+                while(list.size() > 0) 
+                {
+                    messageSet.addChild(MsgBoxUtils.reader2OMElement(new StringReader(list.removeFirst())));
+                    i++;
+                }
+            else if(logger.isDebugEnabled())
+                logger.info("   no messages..");
+        }
+        catch(Exception e)
+        {
+            logger.fatal((new StringBuilder()).append("error taking mesages.. of message box.. - ").append(key).toString(), e);
+        }
+        respEl.addChild(messageSet);
+        respEl.declareNamespace(MsgBoxNameSpConsts.MSG_BOX);
+        return respEl;
+    }
+
+    public OMElement destroyMsgBox(ProcessingContext procCtxt)
+        throws Exception
+    {
+        String addr = "";
+        OMElement statusEl = factory.createOMElement(new QName(ProcessingContext.DESTROY_MSGBOX_RESP_QNAME.getNamespaceURI(), "status"));
+        if(procCtxt.getMsgBoxAddr() != null)
+        {
+            addr = procCtxt.getMsgBoxAddr();
+            storage.destroyMsgBox(addr);
+            statusEl.setText("true");
+        } else
+        {
+            statusEl.setText("false");
+        }
+        OMElement respEl = factory.createOMElement(ProcessingContext.DESTROY_MSGBOX_RESP_QNAME);
+        respEl.addChild(statusEl);
+        return respEl;
+    }
+
+    public void removeAncientMessages()
+    {
+        throw new UnsupportedOperationException("Do not support in memory tmeout of messages");
+    }
+
+    public void setMap2()
+    {
+        logger.debug("storing the map.. method..\n");
+        if(!dbImplenented)
+        {
+            InMemoryImpl mem = (InMemoryImpl)storage;
+            map = mem.getMap();
+        }
+    }
+
+    private static OMFactory factory = OMAbstractFactory.getOMFactory();
+    private static MsgBoxStorage storage;
+    boolean dbImplenented;
+    static Logger logger = Logger.getLogger(MsgBoxServiceSkeleton.class);
+    ConcurrentHashMap map;
+
+}

Propchange: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/MsgBoxServiceSkeleton.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/ProcessingContext.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/ProcessingContext.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/ProcessingContext.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/ProcessingContext.java Sat May 14 18:34:50 2011
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox;
+
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+
+public class ProcessingContext
+{
+
+    public ProcessingContext()
+    {
+    }
+
+    public OMElement getMessage()
+    {
+        return localMessage;
+    }
+
+    public void setMessage(OMElement param)
+    {
+        localMessage = param;
+    }
+
+    public String getMsgBoxAddr()
+    {
+        return localMsgBoxAddr;
+    }
+
+    public void setMsgBoxId(String param)
+    {
+        localMsgBoxAddr = param;
+    }
+
+    public String getMessageId()
+    {
+        return messageID;
+    }
+
+    public void setMessageId(String param)
+    {
+        messageID = param;
+    }
+
+    public String getSoapAction()
+    {
+        return soapAction;
+    }
+
+    public void setSoapAction(String param)
+    {
+        soapAction = param;
+    }
+
+    protected OMElement localMessage;
+    protected String soapAction;
+    protected String messageID;
+    protected String localMsgBoxAddr;
+    public static final QName STOREMSG_QNAME = new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "storeMessages", "msg");
+    public static final QName DESTROYMSG_QNAME = new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "destroyMsgBox", "msg");
+    public static final QName TAKEMSGS_QNAME = new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "takeMessages", "ns1");
+    public static final QName CREATEMSG_BOX = new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "createMsgBox", "msg");
+    public static final QName STOREMSG_RESP_QNAME = new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "storeMessagesResponse", "msg");
+    public static final QName DESTROY_MSGBOX_RESP_QNAME = new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "destroyMsgBoxResponse", "ns1");
+    public static final QName CREATE_MSGBOX_RESP_QNAME = new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/", "createMsgBoxResponse", "msg");
+
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/ConnectionPool.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/ConnectionPool.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/ConnectionPool.java Sat May 14 18:34:50 2011
@@ -0,0 +1,358 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.Storage.DB_Pool;
+
+/**
+ * Modified from book:Core Servlets and JavaServer Pages
+ * http://pdf.coreservlets.com/CSAJSP-Chapter18.pdf
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.sql.DataSource;
+
+import org.apache.log4j.Logger;
+
+/**
+ * A class for preallocating, recycling, and managing JDBC connections.
+ */
+public class ConnectionPool implements Runnable {
+    private long MAX_IDLE_TIME = 5 * 60 * 1000; //5 minutes
+    private String driver, url, username, password, jdbcUrl;
+
+    private int initialConnections, maxConnections;
+
+    private boolean waitIfBusy;
+
+    private Vector availableConnections, busyConnections;
+
+    private boolean connectionPending = false;
+
+    private HashMap lastAccessTimeRecord = new HashMap();
+
+    private String urlType = "";
+
+    private DataSource datasource;
+
+    private boolean autoCommit = true;
+
+    private int transactionIsolation = Connection.TRANSACTION_NONE;
+    static Logger logger = Logger.getLogger(ConnectionPool.class);
+
+    public ConnectionPool(String driver, String url, String username,
+                          String password, int initialConnections, int maxConnections,
+                          boolean waitIfBusy) throws SQLException {
+        this(initialConnections, maxConnections, waitIfBusy);
+        this.driver = driver;
+        this.url = url;
+        this.username = username;
+        this.password = password;
+        urlType = "speratedURL";
+        createConnectionPool();
+    }
+
+    public ConnectionPool(String driver, String jdbcUrl,
+                          int initialConnections, int maxConnections, boolean waitIfBusy, boolean autoCommit, int transactionIsolation)
+            throws SQLException {
+        this(initialConnections, maxConnections, waitIfBusy);
+        this.driver = driver;
+        this.jdbcUrl = jdbcUrl;
+        urlType = "simpleURL";
+        this.autoCommit = autoCommit;
+        this.transactionIsolation = transactionIsolation;
+        createConnectionPool();
+    }
+
+    public ConnectionPool(String driver, String jdbcUrl,
+                          int initialConnections, int maxConnections, boolean waitIfBusy)
+            throws SQLException {
+        this(initialConnections, maxConnections, waitIfBusy);
+        this.driver = driver;
+        this.jdbcUrl = jdbcUrl;
+        urlType = "simpleURL";
+        createConnectionPool();
+    }
+
+    public ConnectionPool(DataSource dataSource, int initialConnections,
+                          int maxConnections, boolean waitIfBusy) throws SQLException {
+        this(initialConnections, maxConnections, waitIfBusy);
+        urlType = "dataSource";
+        this.datasource = dataSource;
+        createConnectionPool();
+    }
+
+    protected ConnectionPool(int initialConnections, int maxConnections, boolean waitIfBusy) throws SQLException {
+        this.initialConnections = initialConnections;
+        this.maxConnections = maxConnections;
+        this.waitIfBusy = waitIfBusy;
+        if (initialConnections > maxConnections) {
+            initialConnections = maxConnections;
+        }
+        availableConnections = new Vector(initialConnections);
+        busyConnections = new Vector();
+        CleanUpThread cleanUpThread = new CleanUpThread();
+        new Thread(cleanUpThread).start();
+    }
+
+    private void createConnectionPool() throws SQLException {
+        for (int i = 0; i < initialConnections; i++) {
+            availableConnections.addElement(makeNewConnection());
+        }
+    }
+
+    public synchronized Connection getConnection() throws SQLException {
+        if (!availableConnections.isEmpty()) {
+            Connection existingConnection = (Connection) availableConnections
+                    .lastElement();
+            int lastIndex = availableConnections.size() - 1;
+            //	System.out.println("ConnectionNo="+lastIndex);
+            availableConnections.removeElementAt(lastIndex);
+
+            long lastAccess = ((Long) lastAccessTimeRecord.get(existingConnection)).longValue();
+            // If connection on available list is closed (e.g.,
+            // it timed out), then remove it from available list
+            // and repeat the process of obtaining a connection.
+            // Also wake up threads that were waiting for a
+            // connection because maxConnection limit was reached.
+            if (existingConnection.isClosed()) {
+                notifyAll(); // Freed up a spot for anybody waiting
+                Connection connection = getConnection();
+                setTimeStamp(connection);
+                return (connection);
+            } else {
+                busyConnections.addElement(existingConnection);
+                setTimeStamp(existingConnection);
+                return existingConnection;
+            }
+        } else {
+            // Three possible cases:
+            // 1) You haven't reached maxConnections limit. So
+            // establish one in the background if there isn't
+            // already one pending, then wait for
+            // the next available connection (whether or not
+            // it was the newly established one).
+            // 2) You reached maxConnections limit and waitIfBusy
+            // flag is false. Throw SQLException in such a case.
+            // 3) You reached maxConnections limit and waitIfBusy
+            // flag is true. Then do the same thing as in second
+            // part of step 1: wait for next available connection.
+            if ((totalConnections() < maxConnections) && !connectionPending) {
+                makeBackgroundConnection();
+            } else if (!waitIfBusy) {
+                throw new SQLException("Connection limit reached");
+            }
+            // Wait for either a new connection to be established
+            // (if you called makeBackgroundConnection) or for
+            // an existing connection to be freed up.
+            try {
+                wait();
+            } catch (InterruptedException ie) {
+            }
+            // Someone freed up a connection, so try again.
+            Connection connection = getConnection();
+            setTimeStamp(connection);
+            return connection;
+        }
+    }
+
+    // You can't just make a new connection in the foreground
+    // when none are available, since this can take several
+    // seconds with a slow network connection. Instead,
+    // start a thread that establishes a new connection,
+    // then wait. You get woken up either when the new connection
+    // is established or if someone finishes with an existing
+    // connection.
+    private void makeBackgroundConnection() {
+        connectionPending = true;
+        try {
+            Thread connectThread = new Thread(this);
+            connectThread.start();
+        } catch (OutOfMemoryError oome) {
+            // Give up on new connection
+        }
+    }
+
+    public void run() {
+        try {
+            Connection connection = makeNewConnection();
+            synchronized (this) {
+                availableConnections.addElement(connection);
+                connectionPending = false;
+                notifyAll();
+            }
+        } catch (Exception e) { // SQLException or OutOfMemory
+            // Give up on new connection and wait for existing one
+            // to free up.
+        }
+    }
+
+    // This explicitly makes a new connection. Called in
+    // the foreground when initializing the ConnectionPool,
+    // and called in the background when running.
+    private Connection makeNewConnection() throws SQLException {
+        try {
+            // Load database driver if not already loaded
+            Class.forName(driver);
+            Connection connection;
+            // Establish network connection to database
+            if (urlType.equals("speratedURL")) {
+                connection = DriverManager.getConnection(url, username,
+                        password);
+            } else if (urlType.equals("simpleURL")) {
+                connection = DriverManager.getConnection(jdbcUrl);
+            } else {   //if(urlType.equals("dataSource")){
+                connection = datasource.getConnection();
+
+            }
+            connection.setTransactionIsolation(this.transactionIsolation);
+            connection.setAutoCommit(this.autoCommit);
+            setTimeStamp(connection);
+            return connection;
+        } catch (ClassNotFoundException cnfe) {
+            // Simplify try/catch blocks of people using this by
+            // throwing only one exception type.
+            throw new SQLException("Can't find class for driver: " + driver);
+        }
+    }
+
+
+    private void setTimeStamp(Connection connection) {
+        lastAccessTimeRecord.put(connection, Long.valueOf(System.currentTimeMillis()));
+    }
+
+    //The database connection cannot be left idle for too long, otherwise TCP connection will be broken.
+    /**
+     * From http://forums.mysql.com/read.php?39,28450,57460#msg-57460
+     * Okay, then it looks like wait_timeout on the server is killing your connection
+     * (it is set to 8 hours of idle time by default). Either set that value higher on your server,
+     * or configure your connection pool to not hold connections idle that long (I prefer the latter).
+     * Most folks I know that run MySQL with a connection pool in high-load production environments only
+     * let connections sit idle for a matter of minutes, since it only takes a few milliseconds to open a connection,
+     * and the longer one sits idle the more chance it will go "bad" because of a network hiccup or the MySQL server
+     * being restarted.
+     *
+     * @throws SQLException
+     */
+    private boolean isConnectionStale(Connection connection) throws SQLException {
+        long currentTime = System.currentTimeMillis();
+        long lastAccess = ((Long) lastAccessTimeRecord.get(connection)).longValue();
+        if (currentTime - lastAccess > MAX_IDLE_TIME) {
+//		   connection.close();
+            //	   System.out.println("*************JDBC Connection Stale!");
+            return true;
+        } else
+            return false;
+    }
+
+    private void closeStaleConnections() throws SQLException {
+        //close idle connections
+        Iterator iter = availableConnections.iterator();
+        while (iter.hasNext()) {
+            Connection existingConnection = (Connection) iter.next();
+            if (isConnectionStale(existingConnection)) {
+                existingConnection.close();
+                iter.remove();
+            }
+        }
+        //close busy connections that have been checked out for too long.
+        //This should not happen sinc ethis means program has bug for not releasing connections .
+        iter = busyConnections.iterator();
+        while (iter.hasNext()) {
+            Connection busyConnection = (Connection) iter.next();
+            if (isConnectionStale(busyConnection)) {
+                iter.remove();
+                busyConnection.close();
+                logger.warn("****Connection has checked out too long. Forced release. Check the program for unReleased connection.");
+            }
+        }
+    }
+
+    public synchronized void free(Connection connection) {
+        busyConnections.removeElement(connection);
+        availableConnections.addElement(connection);
+        // Wake up threads that are waiting for a connection
+        notifyAll();
+    }
+
+    public synchronized int totalConnections() {
+        return (availableConnections.size() + busyConnections.size());
+    }
+
+    /**
+     * Close all the connections. Use with caution: be sure no connections are
+     * in use before calling. Note that you are not <I>required</I> to call
+     * this when done with a ConnectionPool, since connections are guaranteed to
+     * be closed when garbage collected. But this method gives more control
+     * regarding when the connections are closed.
+     */
+    public synchronized void closeAllConnections() {
+        closeConnections(availableConnections);
+        availableConnections = new Vector();
+        closeConnections(busyConnections);
+        busyConnections = new Vector();
+        lastAccessTimeRecord.clear();
+    }
+
+    private void closeConnections(Vector connections) {
+        try {
+            for (int i = 0; i < connections.size(); i++) {
+                Connection connection = (Connection) connections.elementAt(i);
+                if (!connection.isClosed()) {
+                    connection.close();
+                }
+            }
+        } catch (SQLException sqle) {
+            // Ignore errors; garbage collect anyhow
+        }
+    }
+
+    public synchronized String toString() {
+        String info = "ConnectionPool(" + url + "," + username + ")"
+                + ", available=" + availableConnections.size() + ", busy="
+                + busyConnections.size() + ", max=" + maxConnections;
+        return (info);
+    }
+
+    class CleanUpThread implements Runnable {
+        public void run() {
+            while (true) {
+                try {
+                    Thread.sleep(MAX_IDLE_TIME);
+                } catch (InterruptedException e) {
+                    logger.warn(e);
+                }
+                try {
+                    closeStaleConnections();
+                } catch (SQLException e) {
+                    logger.warn(e);
+                    //e.printStackTrace();
+                }
+            }
+        }
+    }
+
+
+}
+

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/DatabaseStorageImpl.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/DatabaseStorageImpl.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/DatabaseStorageImpl.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/DatabaseStorageImpl.java Sat May 14 18:34:50 2011
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.Storage.DB_Pool;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+
+import edu.indiana.extreme.www.xgws.msgbox.Storage.MsgBoxStorage;
+
+/**
+ * @author Chathura Herath (cherath@cs.indiana.edu)
+ */
+
+public class DatabaseStorageImpl implements MsgBoxStorage {
+
+	// private MessageBoxDB messageBoxDB;
+
+	// private final static MLogger logger = MLogger.getLogger();
+
+	public DatabaseStorageImpl(JdbcStorage db) throws SQLException {
+		MessageBoxDB.setJdbcStorage(db);
+	}
+
+	public String createMsgBox() throws SQLException, IOException {
+		// String uuid = FastUUIDGen.nextUUID();// generate uuid
+
+		String uuid = UUID.randomUUID().toString();
+		MessageBoxDB.createMsgBx(uuid, "msgBoxes");
+		return uuid;
+	}
+
+	public void destroyMsgBox(String key) throws Exception {
+		try {
+			MessageBoxDB.deleteMessageBox(key);
+		} catch (SQLException e) {
+			throw new Exception("Could not destroy the message box with key "
+					+ key, e);
+		}
+		// logger.finest("Message box with key " + key +
+		// " was destroyed successfully");
+
+	}
+
+	public List<String> takeMessagesFromMsgBox(String key) throws Exception {
+		// String[] message;
+		List<String> list = null;
+
+		try {
+			list = MessageBoxDB.removeAllMessagesforClient(key);
+
+		} catch (SQLException e) {
+			throw new Exception(
+					"Error reading the message with the key " + key, e);
+		} catch (IOException e) {
+			throw new Exception(
+					"Error reading the message with the key " + key, e);
+		}
+
+		return list;
+	}
+
+	public void putMessageIntoMsgBox(String msgBoxID, String messageID,
+			String soapAction, OMElement message) throws SQLException,
+			IOException, XMLStreamException {
+		MessageBoxDB.addMessage(msgBoxID, messageID, soapAction, message);
+	}
+
+	public void removeAncientMessages() throws Exception {
+		MessageBoxDB.removeAncientMessages();
+
+	}
+
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/JdbcStorage.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/JdbcStorage.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/JdbcStorage.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/JdbcStorage.java Sat May 14 18:34:50 2011
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.Storage.DB_Pool;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import edu.indiana.extreme.www.xgws.msgbox.util.ConfigKeys;
+import edu.indiana.extreme.www.xgws.msgbox.util.ConfigurationManager;
+
+// import edu.indiana.extreme.www.xgws.msgbox._2004.Storage.DB_Pool/db.config 
+
+public class JdbcStorage {
+	// private ConfigurationParamsReader config;
+
+	// private String jdbcUrl=
+	// "jdbc:mysql://156.56.104.175:3306/wsnt?user=root";
+	private String jdbcUrl = null;
+
+	private String messagePreservationDays;
+
+	private String messagePreservationHours;
+
+	private String messagePreservationMinutes;
+
+	private PreparedStatement stmt = null;
+
+	private ResultSet rs = null;
+
+	private ResultSetMetaData rsmd = null;
+
+	// private Connection conn = null;
+	private ConnectionPool connectionPool;
+
+	private String jdbcDriver;
+
+	public JdbcStorage(boolean enableTransactions, ConfigurationManager configs) {
+
+		jdbcUrl = configs.getConfig(ConfigKeys.MSG_BOX_JDBC_URL);
+		jdbcDriver = configs.getConfig(ConfigKeys.JDBC_DRIVER);
+		this.messagePreservationDays = configs
+				.getConfig(ConfigKeys.MSG_PRESV_DAYS);
+		this.messagePreservationHours = configs
+				.getConfig(ConfigKeys.MSG_PRESV_HRS);
+		this.messagePreservationMinutes = configs
+				.getConfig(ConfigKeys.MSG_PRESV_MINS);
+
+		try {
+			if (enableTransactions) {
+				connectionPool = new ConnectionPool(jdbcDriver, jdbcUrl, 10,
+						50, true, false, Connection.TRANSACTION_SERIALIZABLE);
+			} else {
+				connectionPool = new ConnectionPool(jdbcDriver, jdbcUrl, 10,
+						50, true);
+			}
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			// e.printStackTrace();
+			throw new RuntimeException(
+					"Failed to create database connection poll.", e);
+		}
+
+	}
+
+	public Connection connect() throws SQLException {
+
+		Connection conn = connectionPool.getConnection();
+		return conn;
+	}
+
+	public void closeConnection(Connection conn) throws java.sql.SQLException {
+
+		connectionPool.free(conn);
+	}
+
+	public int update(String query) throws java.sql.SQLException {
+		int result = 0;
+		// connect();
+		Connection conn = connectionPool.getConnection();
+		stmt = conn.prepareStatement(query);
+		result = stmt.executeUpdate();
+		stmt.close();
+		connectionPool.free(conn);
+
+		return result;
+	}
+
+	/**
+	 * This method is provided so that yo can have better control over the
+	 * statement. For example: You can use stmt.setString to convert quotation
+	 * mark automatically in an INSERT statement
+	 */
+	public int insert(PreparedStatement stmt) throws java.sql.SQLException {
+		int rows = 0;
+
+		rows = stmt.executeUpdate();
+		stmt.close();
+		return rows;
+	}
+
+	public int insert(String query) throws java.sql.SQLException {
+		int rows = 0;
+
+		Connection conn = connectionPool.getConnection();
+		stmt = conn.prepareStatement(query);
+		rows = stmt.executeUpdate();
+		stmt.close();
+		connectionPool.free(conn);
+
+		return rows;
+	}
+
+	public ResultSet query(String query) throws SQLException {
+		Connection conn = connectionPool.getConnection();
+		// Create a scrollable ResultSet so that I can use rs.last() to get
+		// total number of rows without using another COUNT in SQL query
+		Statement lstmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
+				ResultSet.CONCUR_READ_ONLY);
+		ResultSet rs = lstmt.executeQuery(query);
+		connectionPool.free(conn);
+		return rs;
+	}
+
+	public int countRow(String tableName, String columnName)
+			throws java.sql.SQLException {
+		String query = new String("SELECT COUNT(" + columnName + ") FROM "
+				+ tableName);
+		Connection conn = connectionPool.getConnection();
+		stmt = conn.prepareStatement(query);
+		rs = stmt.executeQuery();
+		rs.next();
+		int count = rs.getInt(1);
+		stmt.close();
+		connectionPool.free(conn);
+		return count;
+	}
+
+	public int getMessagePreservationDays() {
+		return Integer.parseInt(messagePreservationDays);
+	}
+
+	public int getMessagePreservationHours() {
+		return Integer.parseInt(messagePreservationHours);
+	}
+
+	public int getMessagePreservationMinutes() {
+		return Integer.parseInt(messagePreservationMinutes);
+	}
+
+	public long getInterval() {
+		long interval = this.getMessagePreservationDays() * 24;
+		interval = (interval + this.getMessagePreservationHours()) * 60;
+		interval = (interval + this.getMessagePreservationMinutes()) * 60;
+		interval = interval * 1000;
+		return interval;
+	}
+
+	public void closeAllConnections() {
+		if (connectionPool != null)
+			connectionPool.closeAllConnections();
+	}
+
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/MessageBoxDB.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/MessageBoxDB.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/MessageBoxDB.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/DB_Pool/MessageBoxDB.java Sat May 14 18:34:50 2011
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.Storage.DB_Pool;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.log4j.Logger;
+
+/**
+ * @author dinesh
+ */
+
+public class MessageBoxDB {
+
+	static Logger logger = Logger.getLogger(MessageBoxDB.class);
+
+	private static Set<String> msgBoxids;
+
+	public static final String SELECT_ALL_FROM_MSGBOXES = "SELECT * FROM msgBoxes";
+
+	private static JdbcStorage db;
+
+	public static String SQL_STORE_MESSAGE_STATEMENT = "INSERT INTO msgbox (xml, msgboxid, messageid,soapaction) VALUES (?,?,?,?)";
+
+	public static String SQL_CREATE_MSGBOX_STATEMENT = "INSERT INTO %s (msgboxid) VALUES ('%s')";
+
+	public static String SQL_DELETE_ALL_STATEMENT = "DELETE FROM %s WHERE msgboxid='%s'";
+
+	public static String SQL_SELECT_STATEMENT1 = "SELECT * FROM %s WHERE msgboxid='%s' ORDER BY '%s' DESC";
+
+	public static String SQL_DELETE_ANCIENT_STATEMENT = "DELETE FROM %s WHERE time <'%s'";
+
+	public MessageBoxDB(JdbcStorage db) {
+		this.db = db;
+	}
+
+	public static void createMsgBx(String messageBoxId, String tableName)
+			throws SQLException, IOException {
+		if (!msgBoxids.contains(messageBoxId)) {
+			Connection connection = db.connect();
+			Statement statement = connection.createStatement();
+			statement.execute(String.format(SQL_CREATE_MSGBOX_STATEMENT,
+					tableName, messageBoxId));
+			connection.commit();
+			db.closeConnection(connection);
+			msgBoxids.add(messageBoxId);
+		} else
+			throw new AxisFault("The message box ID requested already exists");
+	}
+
+	public static void addMessage(String msgBoxID, String messageID,
+			String soapAction, OMElement message) throws SQLException,
+			IOException, XMLStreamException {
+		if (msgBoxids.contains(msgBoxID)) {
+			Connection connection = db.connect();
+			PreparedStatement stmt = connection
+					.prepareStatement(SQL_STORE_MESSAGE_STATEMENT);
+			byte[] buffer;
+			ByteArrayOutputStream output = new ByteArrayOutputStream();
+			ObjectOutputStream out = new ObjectOutputStream(output);
+			out.writeObject(message.toStringWithConsume());
+			buffer = output.toByteArray();
+			ByteArrayInputStream in = new ByteArrayInputStream(buffer);
+			stmt.setBinaryStream(1, in, buffer.length);
+			stmt.setString(2, msgBoxID);
+			stmt.setString(3, messageID);
+			stmt.setString(4, soapAction);
+			db.insert(stmt);
+			stmt.close();
+			connection.commit();
+			db.closeConnection(connection);
+		} else {
+			throw new AxisFault(
+					"Currently a messagebox is not available with given message box id :"
+							+ msgBoxID);
+		}
+	}
+
+	public static void deleteMessageBox(String msgBoxId) throws SQLException {
+
+		if (msgBoxids.contains(msgBoxId)) {
+			Connection connection = db.connect();
+			Statement statement = connection.createStatement();
+			statement.execute(String.format(SQL_DELETE_ALL_STATEMENT, "msgbox",
+					msgBoxId));
+			statement.execute(String.format(SQL_DELETE_ALL_STATEMENT,
+					"msgBoxes", msgBoxId));
+			db.closeConnection(connection);
+			msgBoxids.remove(msgBoxId);
+		}
+	}
+
+	public static List<String> removeAllMessagesforClient(String msgBoxId)
+			throws SQLException, IOException, ClassNotFoundException,
+			XMLStreamException {
+		LinkedList<String> list = new LinkedList<String>();
+		if (msgBoxids.contains(msgBoxId)) {
+			Connection connection = db.connect();
+
+			PreparedStatement stmt = connection.prepareStatement(String.format(
+					SQL_SELECT_STATEMENT1, "msgbox", msgBoxId, String.format(
+							"%s.%s", "msgbox", "id")));
+			ResultSet resultSet = stmt.executeQuery();
+			resultSet.beforeFirst();
+
+			while (resultSet.next()) {
+				InputStream in = resultSet.getAsciiStream("xml");
+				ObjectInputStream s = new ObjectInputStream(in);
+				String xmlString = (String) s.readObject();
+				System.out.println(xmlString);
+				list.addFirst(xmlString);
+			}
+			resultSet.close();
+			stmt.close();
+			stmt = connection.prepareStatement(String.format(
+					SQL_DELETE_ALL_STATEMENT, "msgbox", msgBoxId));
+			db.insert(stmt);
+			stmt.close();
+			connection.commit();
+			db.closeConnection(connection);
+		}
+		return list;
+	}
+
+	public static void removeAncientMessages() {
+		try {
+			Connection connection = db.connect();
+			long interval = db.getInterval();
+			long persevetime = (System.currentTimeMillis() - interval);
+			PreparedStatement stmt = connection.prepareStatement(String.format(
+					SQL_DELETE_ANCIENT_STATEMENT, "msgBox", persevetime));
+			db.insert(stmt);
+			stmt.close();
+			db.closeConnection(connection);
+		} catch (SQLException e) {
+			logger
+					.fatal(
+							"Caught exception while removing old entries from msgbox db table",
+							e);
+		}
+
+	}
+
+	public static void setJdbcStorage(JdbcStorage db2) throws SQLException {
+		db = db2;
+		setMsgBoxidList();
+
+	}
+
+	private static void setMsgBoxidList() throws SQLException {
+		msgBoxids = Collections.synchronizedSet(new HashSet<String>());
+		Connection connection = db.connect();
+		Statement statement = connection.createStatement();
+		ResultSet resultSet = statement.executeQuery(SELECT_ALL_FROM_MSGBOXES);
+		while (resultSet.next()) {
+			msgBoxids.add(resultSet.getString("msgboxid"));
+		}
+		statement.close();
+		connection.commit();
+		db.closeConnection(connection);
+	}
+
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/MsgBoxStorage.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/MsgBoxStorage.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/MsgBoxStorage.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/MsgBoxStorage.java Sat May 14 18:34:50 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package edu.indiana.extreme.www.xgws.msgbox.Storage;
+
+import java.util.List;
+
+import org.apache.axiom.om.OMElement;
+
+
+/**
+ * Message Box storage backend.
+ */
+public interface MsgBoxStorage {
+    public String createMsgBox() throws Exception;
+
+    // DELETE FROM msgbox WHERE msgboxid=key
+    public void destroyMsgBox(String key) throws Exception;
+
+    // SELECT * FROM msgbox WHERE msgboxid=key ORDER BY id LIMIT 1
+    // DELETE FROM msgbox WHERE msgboxid=key AND id=*
+    public List<String> takeMessagesFromMsgBox(String key) throws Exception;
+
+    // INSERT INTO msgbox ...
+    public void putMessageIntoMsgBox(String msgBoxID, String messageID, String soapAction, OMElement message) throws Exception;
+
+    /**
+     * The ancientness is defined in the db.config file.
+     */
+    public void removeAncientMessages() throws Exception;
+
+    //public void closeConnection() throws Exception;
+}

Propchange: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/MsgBoxStorage.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/memory/InMemoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/memory/InMemoryImpl.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/memory/InMemoryImpl.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/memory/InMemoryImpl.java Sat May 14 18:34:50 2011
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.Storage.memory;
+
+import java.util.LinkedList;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.log4j.Logger;
+
+import edu.indiana.extreme.www.xgws.msgbox.Storage.MsgBoxStorage;
+
+
+public class InMemoryImpl implements MsgBoxStorage {
+    static Logger logger = Logger.getLogger(InMemoryImpl.class);
+
+
+    ConcurrentHashMap<String, LinkedList<String>> map;
+
+    public ConcurrentHashMap<String, LinkedList<String>> getMap() {
+        return map;
+    }
+
+    public void setMap(ConcurrentHashMap<String, LinkedList<String>> map) {
+        this.map = map;
+    }
+
+    public String createMsgBox() throws Exception {
+
+    	String clientid = UUID.randomUUID().toString();
+        lookupQueue(clientid); //that will create an empty queue
+        return clientid;
+    }
+
+    public void destroyMsgBox(String key) throws Exception {
+         if (map.containsKey(key)) 
+            map.remove(key);
+    }
+
+    public  LinkedList<String> takeMessagesFromMsgBox(String key) throws Exception {
+
+        LinkedList<String> list;
+
+        synchronized (map) {
+            list = map.get(key);
+
+            if (list == null)
+                throw new IllegalArgumentException("no message box with key " + key);
+        }
+        return list;
+       
+    }
+
+    public void putMessageIntoMsgBox(String msgBoxID, String messageID, String soapAction, OMElement message) throws Exception {
+
+        //To change body of implemented methods use File | Settings | File Templates.
+        LinkedList<String> list = lookupQueue(msgBoxID);
+        if (list == null) {
+            throw new IllegalArgumentException("no message box with key " + msgBoxID + " to store the msg");
+        }
+        synchronized (list) {
+            list.addLast(message.toStringWithConsume());
+            logger.info("Message Stored in list with key " + msgBoxID);
+        }
+    }
+
+    /**
+     * The ancientness is defined in the db.config file.
+     */
+    public void removeAncientMessages() {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void closeConnection() throws Exception {
+        //TODOn - store map back
+    }
+
+    private LinkedList<String> lookupQueue(String key) {
+
+        logger.debug("lookupQueue: calling the getMap method...");
+
+        if (key == null) throw new IllegalArgumentException();
+        synchronized (map) {
+            LinkedList<String> v = map.get(key);
+            logger.debug(key + " is being searched in map..");
+
+            if (v != null) {
+                logger.info("key found in map.. " + key);
+                return v;
+            }
+
+            logger.info("key not found in map.. " + key);
+            LinkedList<String> list = new LinkedList<String>();
+            map.put(key, list);
+            logger.debug("new list created in map.. calling the setMap method...");
+            //this.setMap(map);
+            return list;
+        }
+    }
+}

Propchange: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/Storage/memory/InMemoryImpl.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/StoreMessageHandler.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/StoreMessageHandler.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/StoreMessageHandler.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/StoreMessageHandler.java Sat May 14 18:34:50 2011
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox;
+
+import java.util.List;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.AddressingFaultsHelper;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.dispatchers.AddressingBasedDispatcher;
+import org.apache.axis2.engine.Phase;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.log4j.Logger;
+
+public class StoreMessageHandler extends AddressingBasedDispatcher {
+	private static final String WSMG_MSGSTORE_SOAP_ACTION = "http://www.extreme.indiana.edu/xgws/msgbox/2004/storeMessages";
+	private static final String ADDRESSING_VALIDATE_ACTION = "addressing.validateAction";
+	Logger logger = Logger.getLogger(StoreMessageHandler.class);
+	private Phase addressingPhase = null;
+
+	private AxisOperation messageBoxOperation = null;
+
+	public StoreMessageHandler() {
+
+	}
+
+	public org.apache.axis2.engine.Handler.InvocationResponse invoke(
+			MessageContext msgContext) throws AxisFault {
+
+		InvocationResponse response = InvocationResponse.CONTINUE;
+		if (msgContext.getAxisService() == null
+				|| msgContext.getAxisOperation() == null) {
+
+			boolean validateAction = JavaUtils.isTrue(msgContext
+					.getProperty(ADDRESSING_VALIDATE_ACTION), true);
+			msgContext.setProperty(ADDRESSING_VALIDATE_ACTION, Boolean
+					.valueOf(false));
+
+			response = super.invoke(msgContext);
+
+			if (isForMessageBoxService(msgContext))
+				validateMsgBoxStoreOperation(msgContext);
+			if (validateAction)
+				checkAction(msgContext);
+			msgContext.setProperty(ADDRESSING_VALIDATE_ACTION, Boolean
+					.valueOf(validateAction));
+
+		}
+		return response;
+	}
+
+	private void validateMsgBoxStoreOperation(MessageContext msgContext) {
+		if (msgContext.getAxisOperation() == null) {
+			AxisService service = msgContext.getAxisService();
+			AxisOperation storeMsgOperation = getMessageBoxOperation(service);
+
+			msgContext.setAxisOperation(storeMsgOperation);
+		}
+	}
+
+	private boolean isForMessageBoxService(MessageContext msgContext) {
+		return msgContext.getAxisService() != null
+				&& msgContext.getAxisService().getName()
+						.equals("MsgBoxService");
+	}
+
+	private AxisOperation getMessageBoxOperation(AxisService msgBoxService) {
+		if (messageBoxOperation == null)
+			messageBoxOperation = msgBoxService
+					.getOperationBySOAPAction(WSMG_MSGSTORE_SOAP_ACTION);
+		return messageBoxOperation;
+	}
+
+	private void checkAction(MessageContext msgContext) throws AxisFault {
+
+		Phase addPhase = getAddressingPhase(msgContext);
+
+		if (addPhase == null) {
+			logger.error("unable to locate addressing phase object");
+		}
+
+		if (msgContext.getCurrentPhaseIndex() + 1 == addPhase.getHandlerCount()) {
+			if (msgContext.getAxisService() == null
+					|| msgContext.getAxisOperation() == null)
+				AddressingFaultsHelper.triggerActionNotSupportedFault(
+						msgContext, msgContext.getWSAAction());
+		}
+
+	}
+
+	private Phase getAddressingPhase(MessageContext context) {
+
+		if (addressingPhase == null) {
+
+			List<Phase> inFlowPhases = context.getConfigurationContext()
+					.getAxisConfiguration().getPhasesInfo().getINPhases();
+
+			for (Phase p : inFlowPhases) {
+				if (p.getName().equalsIgnoreCase("Addressing")) {
+					addressingPhase = p;
+				}
+			}
+
+		}
+
+		return addressingPhase;
+
+	}
+
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/CreateMsgBox.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/CreateMsgBox.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/CreateMsgBox.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/CreateMsgBox.java Sat May 14 18:34:50 2011
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.client;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.log4j.Logger;
+
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxCommonConstants;
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxNameSpConsts;
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxUtils;
+
+public class CreateMsgBox {
+	org.apache.log4j.Logger logger = Logger.getLogger(CreateMsgBox.class);
+	private final OMFactory factory = OMAbstractFactory.getOMFactory();
+	protected String msgBoxEndPointReference;
+	protected long timeoutInMilliSeconds;
+	private String msgBoxId;
+	private OMElement responseEl;
+
+	public CreateMsgBox(String msgBoxLocation, long timeout) {
+		this.msgBoxEndPointReference = msgBoxLocation;
+		responseEl = OMAbstractFactory.getOMFactory().createOMElement(
+				new QName("http://www.extreme.indiana.edu/xgws/msgbox/2004/",
+						"MsgBoxId"));
+
+		timeoutInMilliSeconds = timeout;
+	}
+
+	public long getTimeoutInMilliSeconds() {
+		return timeoutInMilliSeconds;
+	}
+
+	public void setTimeoutInMilliSeconds(long timeout) {
+		timeoutInMilliSeconds = timeout;
+	}
+
+	public EndpointReference execute() throws AxisFault {
+		ServiceClient serviceClient = createServiceClient();
+		OMElement responseMessage = null;
+		try {
+			responseMessage = serviceClient.sendReceive(createMessageEl());
+		} finally {
+			serviceClient.cleanupTransport();
+		}
+
+		if (responseMessage == null) {
+			throw AxisFault.makeFault(new RuntimeException(
+					"no response recieved for subscription message"));
+		}
+		String response = responseMessage.getFirstElement().getText();
+		this.responseEl.setText(response);
+		this.msgBoxEndPointReference = MsgBoxUtils.formatMessageBoxUrl(
+				this.msgBoxEndPointReference, response);
+		return new EndpointReference(this.msgBoxEndPointReference);
+	}
+
+	private OMElement createMessageEl() throws AxisFault {
+		OMElement message = factory.createOMElement("createMsgBox",
+				MsgBoxNameSpConsts.MSG_BOX);
+		OMElement msgBoxId = factory.createOMElement("MsgBoxId",
+				MsgBoxNameSpConsts.MSG_BOX);
+		msgBoxId.setText("Create message box");
+		message.addChild(msgBoxId);
+		message.declareNamespace(MsgBoxNameSpConsts.MSG_BOX);
+		return message;
+	}
+
+	private ServiceClient createServiceClient() throws AxisFault {
+		String uuid = UUIDGenerator.getUUID();
+		Options opts = new Options();
+		opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
+				Boolean.FALSE);
+		opts.setTo(new EndpointReference(this.msgBoxEndPointReference));
+		opts.setMessageId(uuid);
+		opts.setAction(MsgBoxNameSpConsts.MSG_BOX.getNamespaceURI() + "/"
+				+ "createMsgBox");
+
+		opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+		ServiceClient client = new ServiceClient();
+		try {
+			client
+					.engageModule(MsgBoxCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module engaged");
+		} catch (AxisFault e) {
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module not engaged :" + e);
+		}
+		client.setOptions(opts);
+		return client;
+	}
+
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/DestroyMsgBox.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/DestroyMsgBox.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/DestroyMsgBox.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/DestroyMsgBox.java Sat May 14 18:34:50 2011
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.client;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.log4j.Logger;
+
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxCommonConstants;
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxNameSpConsts;
+
+public class DestroyMsgBox {
+	private EndpointReference msgBoxEndPointReference = null;
+	private long timeoutInMilliSeconds = 0;
+	org.apache.log4j.Logger logger = Logger.getLogger(DestroyMsgBox.class);
+	private String msgBoxId = null;
+	private final OMFactory factory = OMAbstractFactory.getOMFactory();
+
+	public DestroyMsgBox(EndpointReference msgBoxEpr, long timeout)
+			throws AxisFault {
+		this.msgBoxEndPointReference = msgBoxEpr;
+		this.timeoutInMilliSeconds = timeout;
+		String address = msgBoxEpr.getAddress();
+		int biginIndex = address.indexOf("clientid");
+		if (biginIndex != -1) {
+			msgBoxId = address.substring(biginIndex + "clientid".length() + 1);
+		} else {
+			throw new AxisFault(
+					"Invalid Message Box EPR cannot find message box ID");
+		}
+	}
+
+	public long getTimeoutInMilliSeconds() {
+		return timeoutInMilliSeconds;
+	}
+
+	public void setTimeoutInMilliSeconds(long timeout) {
+		timeoutInMilliSeconds = timeout;
+	}
+
+	public String execute() throws AxisFault {
+		OMElement message = createMessageEl(this.msgBoxId);
+		ServiceClient serviceClient = createServiceClient(message);
+
+		OMElement responseMessage = null;
+		try {
+			responseMessage = serviceClient.sendReceive(message);
+		} finally {
+			serviceClient.cleanupTransport();
+		}
+
+		responseMessage = serviceClient.sendReceive(message);
+		if (responseMessage == null) {
+			throw AxisFault.makeFault(new RuntimeException(
+					"no response recieved for subscription message"));
+		}
+		return responseMessage.getFirstElement().getText();
+	}
+
+	private OMElement createMessageEl(String msgboxid) throws AxisFault {
+		OMElement message = factory.createOMElement("destroyMsgBox",
+				MsgBoxNameSpConsts.MSG_BOX);
+		OMElement msgBoxId = factory.createOMElement("MsgBoxId",
+				MsgBoxNameSpConsts.MSG_BOX);
+		msgBoxId.setText(msgboxid);
+		message.addChild(msgBoxId);
+		message.declareNamespace(MsgBoxNameSpConsts.MSG_BOX);
+		return message;
+	}
+
+	private ServiceClient createServiceClient(OMElement message)
+			throws AxisFault {
+		String uuid = UUIDGenerator.getUUID();
+		Options opts = new Options();
+		opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
+				Boolean.FALSE);
+		opts.setTo(msgBoxEndPointReference);
+		opts.setMessageId(uuid);
+		opts.setAction(message.getNamespace().getNamespaceURI() + "/"
+				+ message.getLocalName());
+
+		opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+
+		ServiceClient client = new ServiceClient();
+		try {
+			client
+					.engageModule(MsgBoxCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module engaged");
+		} catch (AxisFault e) {
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module not engaged :" + e);
+		}
+
+		client.setOptions(opts);
+		return client;
+	}
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/MsgBoxClient.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/MsgBoxClient.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/MsgBoxClient.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/MsgBoxClient.java Sat May 14 18:34:50 2011
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.client;
+
+import java.rmi.RemoteException;
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.log4j.Logger;
+
+public class MsgBoxClient {
+
+	int msgsAtOnce = 10;
+	static Logger logger = Logger.getLogger(MsgBoxClient.class);
+
+	public MsgBoxClient() {
+	}
+
+	public EndpointReference createMessageBox(String msgBoxLocation,
+			long timeout) throws RemoteException {
+		CreateMsgBox msgBox = new CreateMsgBox(msgBoxLocation, timeout);
+		return msgBox.execute();
+	}
+
+	public String storeMessage(EndpointReference msgBoxEpr, long timeout,
+			OMElement messageIn) throws RemoteException {
+		StoreMessage strMsg = new StoreMessage(msgBoxEpr, timeout);
+		return strMsg.execute(messageIn);
+	}
+
+	public Iterator<OMElement> takeMessagesFromMsgBox(
+			EndpointReference msgBoxEpr, long timeout) throws RemoteException {
+		TakeMessages takeMsgs = new TakeMessages(msgBoxEpr, timeout);
+		return takeMsgs.execute();
+	}
+
+	public String deleteMsgBox(EndpointReference msgBoxEpr, long timeout)
+			throws RemoteException {
+		DestroyMsgBox destroyMsgBox = new DestroyMsgBox(msgBoxEpr, timeout);
+		return destroyMsgBox.execute();
+	}
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/StoreMessage.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/StoreMessage.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/StoreMessage.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/StoreMessage.java Sat May 14 18:34:50 2011
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.client;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.log4j.Logger;
+
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxCommonConstants;
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxNameSpConsts;
+
+public class StoreMessage {
+	private final OMFactory factory = OMAbstractFactory.getOMFactory();
+	protected EndpointReference msgBoxEndPointReference;
+	protected long timeoutInMilliSeconds;
+	org.apache.log4j.Logger logger = Logger.getLogger(StoreMessage.class);
+	private String msgBoxId;
+
+	public StoreMessage(EndpointReference msgBoxEpr, long timeout)
+			throws AxisFault {
+		this.msgBoxEndPointReference = msgBoxEpr;
+		this.timeoutInMilliSeconds = timeout;
+		String address = msgBoxEpr.getAddress();
+		int biginIndex = address.indexOf("clientid");
+		if (biginIndex != -1) {
+			msgBoxId = address.substring(biginIndex + "clientid".length() + 1);
+		} else {
+			throw new AxisFault(
+					"Invalid Message Box EPR cannot find message box ID");
+		}
+	}
+
+	public long getTimeoutInMilliSeconds() {
+		return timeoutInMilliSeconds;
+	}
+
+	public void setTimeoutInMilliSeconds(long timeout) {
+		timeoutInMilliSeconds = timeout;
+	}
+
+	public String execute(OMElement messageIn) throws AxisFault {
+		// OMElement message = createMessageEl(this.msgBoxId, messageIn);
+		ServiceClient serviceClient = createServiceClient();
+
+		OMElement responseMessage = null;
+
+		try {
+			responseMessage = serviceClient.sendReceive(messageIn);
+		} finally {
+			serviceClient.cleanupTransport();
+		}
+
+		if (responseMessage == null) {
+			throw AxisFault.makeFault(new RuntimeException(
+					"no response recieved for subscription message"));
+		}
+		return responseMessage.getFirstElement().getText();
+	}
+
+	private OMElement createMessageEl(String msgboxid, OMElement messageIn)
+			throws AxisFault {
+		OMElement message = factory.createOMElement("storeMessages",
+				MsgBoxNameSpConsts.MSG_BOX);
+		OMElement messageElement = factory.createOMElement("message",
+				MsgBoxNameSpConsts.MSG_BOX);
+		OMElement msgBoxId = factory.createOMElement("MsgBoxId",
+				MsgBoxNameSpConsts.MSG_BOX);
+		msgBoxId.setText(msgboxid);
+		message.addChild(msgBoxId);
+		messageElement.addChild(messageIn);
+		message.addChild(messageElement);
+		message.declareNamespace(MsgBoxNameSpConsts.MSG_BOX);
+		return message;
+	}
+
+	private ServiceClient createServiceClient() throws AxisFault {
+		String uuid = UUIDGenerator.getUUID();
+		Options opts = new Options();
+		opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
+				Boolean.FALSE);
+		opts.setTo(msgBoxEndPointReference);
+		opts.setMessageId(uuid);
+		opts.setAction(MsgBoxNameSpConsts.MSG_BOX.getNamespaceURI() + "/"
+				+ "storeMessages");
+
+		opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+		ServiceClient client = new ServiceClient();
+		try {
+			client
+					.engageModule(MsgBoxCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module engaged");
+		} catch (AxisFault e) {
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module not engaged :" + e);
+		}
+		client.setOptions(opts);
+		return client;
+	}
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/TakeMessages.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/TakeMessages.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/TakeMessages.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/client/TakeMessages.java Sat May 14 18:34:50 2011
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.client;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.log4j.Logger;
+
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxCommonConstants;
+import edu.indiana.extreme.www.xgws.msgbox.util.MsgBoxNameSpConsts;
+
+public class TakeMessages {
+	private final OMFactory factory = OMAbstractFactory.getOMFactory();
+	protected EndpointReference msgBoxEndPointReference;
+	protected long timeoutInMilliSeconds;
+	private String msgBoxId;
+	org.apache.log4j.Logger logger = Logger.getLogger(TakeMessages.class);
+
+	public TakeMessages(EndpointReference msgBoxEpr, long timeout)
+			throws AxisFault {
+		this.msgBoxEndPointReference = msgBoxEpr;
+		this.timeoutInMilliSeconds = timeout;
+		String address = msgBoxEpr.getAddress();
+		int biginIndex = address.indexOf("clientid");
+		if (biginIndex != -1) {
+			msgBoxId = address.substring(biginIndex + "clientid".length() + 1);
+		} else {
+			throw new AxisFault(
+					"Invalid Message Box EPR cannot find message box ID");
+		}
+	}
+
+	public long getTimeoutInMilliSeconds() {
+		return timeoutInMilliSeconds;
+	}
+
+	public void setTimeoutInMilliSeconds(long timeout) {
+		timeoutInMilliSeconds = timeout;
+	}
+
+	public Iterator<OMElement> execute() throws AxisFault {
+		OMElement message = createMessageEl(this.msgBoxId);
+		ServiceClient serviceClient = createServiceClient(message);
+
+		OMElement responseMessage = null;
+		try {
+			responseMessage = serviceClient.sendReceive(message);
+
+			if (responseMessage == null) {
+				throw AxisFault.makeFault(new RuntimeException(
+						"no response recieved for subscription message"));
+			}
+
+			responseMessage.build(); // free the input stream.
+
+		} finally {
+			serviceClient.cleanupTransport();
+		}
+
+		Iterator<OMElement> children = responseMessage.getFirstElement()
+				.getChildren();
+		return children;
+	}
+
+	private OMElement createMessageEl(String msgboxid) throws AxisFault {
+		OMElement message = factory.createOMElement("takeMessages",
+				MsgBoxNameSpConsts.MSG_BOX);
+		OMElement msgBoxId = factory.createOMElement("MsgBoxId",
+				MsgBoxNameSpConsts.MSG_BOX);
+		msgBoxId.setText(msgboxid);
+		message.addChild(msgBoxId);
+		message.declareNamespace(MsgBoxNameSpConsts.MSG_BOX);
+		return message;
+	}
+
+	private ServiceClient createServiceClient(OMElement message)
+			throws AxisFault {
+		String uuid = UUIDGenerator.getUUID();
+		Options opts = new Options();
+		opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
+				Boolean.FALSE);
+		opts.setTo(msgBoxEndPointReference);
+		opts.setMessageId(uuid);
+		opts.setAction(message.getNamespace().getNamespaceURI() + "/"
+				+ message.getLocalName());
+
+		opts.setTimeOutInMilliSeconds(getTimeoutInMilliSeconds());
+		ServiceClient client = new ServiceClient();
+		try {
+			client
+					.engageModule(MsgBoxCommonConstants.AXIS_MODULE_NAME_ADDRESSING);
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module engaged");
+		} catch (AxisFault e) {
+			if (logger.isDebugEnabled())
+				logger.debug("Addressing module not engaged :" + e);
+		}
+
+		client.setOptions(opts);
+		return client;
+	}
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigKeys.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigKeys.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigKeys.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigKeys.java Sat May 14 18:34:50 2011
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.util;
+
+public class ConfigKeys {
+	public static final String CONFIG_FILE_NAME = "msgBox.properties";
+	public static final String MSG_PRESV_DAYS = "messagePreservationDays";
+	public static final String MSG_PRESV_HRS = "messagePreservationHours";
+	public static final String MSG_PRESV_MINS = "messagePreservationMinutes";
+	public static String JDBC_DRIVER = "msgBox.jdbc.driver";
+	public static String MSG_BOX_JDBC_URL="msgBox.jdbc.url";
+	public static String USE_DATABSE_STORAGE="msgBox.usedatabase";
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigurationManager.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigurationManager.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/ConfigurationManager.java Sat May 14 18:34:50 2011
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package edu.indiana.extreme.www.xgws.msgbox.util;
+
+import java.util.Properties;
+
+public class ConfigurationManager {
+	protected Properties configurations = new Properties();
+
+	public ConfigurationManager(String configFileName) {
+		try {
+			configurations.load(this.getClass().getClassLoader()
+					.getResourceAsStream(configFileName));
+
+		} catch (Exception e) {
+			throw new RuntimeException("unable to load configurations", e);
+		}
+
+	}
+
+	public String getConfig(String configName) {
+
+		return configurations.getProperty(configName);
+	}
+
+	public String getConfig(String configName, String defaultVal) {
+		return configurations.getProperty(configName, defaultVal);
+	}
+}

Added: incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/MsgBoxCommonConstants.java
URL: http://svn.apache.org/viewvc/incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/MsgBoxCommonConstants.java?rev=1103180&view=auto
==============================================================================
--- incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/MsgBoxCommonConstants.java (added)
+++ incubator/airavata/donations/ogce-donation/modules/ws-messaging/msgbox/src/main/java/edu/indiana/extreme/www/xgws/msgbox/util/MsgBoxCommonConstants.java Sat May 14 18:34:50 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Lanka Software Foundation (LSF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The LSF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package edu.indiana.extreme.www.xgws.msgbox.util;
+
+import javax.xml.namespace.QName;
+
+public class MsgBoxCommonConstants {
+
+	public static final String DB_IMPLEMENTED_TRUE = "database.inited";
+	public static final String MSGBOX_STORAGE = "msgbox.storage";
+	public static final String CONF_MANAGER = "conf.manager";
+	public static final String INIT_MSG_BOX_SKELETON_TRUE = "init.msgbox.skeleton";
+	public static final String AXIS_MODULE_NAME_ADDRESSING = "addressing";
+	public static final QName MSG_BOXID_QNAME= new QName(
+			"http://www.extreme.indiana.edu/xgws/msgbox/2004/",
+			"MsgBoxId");
+
+}