You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by am...@apache.org on 2009/12/04 09:22:53 UTC

svn commit: r887103 - in /webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm: GSMImplManager.java GSMServiceRepository.java

Author: amilas
Date: Fri Dec  4 08:22:51 2009
New Revision: 887103

URL: http://svn.apache.org/viewvc?rev=887103&view=rev
Log:
applying the patch for WSCOMMONS-508

Added:
    webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMServiceRepository.java
Modified:
    webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java

Modified: webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java?rev=887103&r1=887102&r2=887103&view=diff
==============================================================================
--- webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java (original)
+++ webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMImplManager.java Fri Dec  4 08:22:51 2009
@@ -55,11 +55,16 @@
     private GSMDispatcher dispatcher;
     private Service service = null;
     private SerialModemGateway gateway;
-
+    private GSMServiceRepository serviceRepo = GSMServiceRepository.getInstence();
     private SMSManager smsInManeger;
     public void start() {
-       
+
+        if(serviceRepo.gatewayInUse(gsmTransportInDetails.getGatewayId())) {
+            service = serviceRepo.getService(gsmTransportInDetails.getGatewayId());
+            return;
+        }
         service = new Service();
+
         gateway= new SerialModemGateway(gsmTransportInDetails.getGatewayId(), gsmTransportInDetails.getComPort(),
                 gsmTransportInDetails.getBaudRate(),gsmTransportInDetails.getManufacturer(),
                 gsmTransportInDetails.getModel());
@@ -84,6 +89,7 @@
 
             // Start! (i.e. connect to all defined Gateways)
             this.service.startService();
+            serviceRepo.addService(gsmTransportInDetails.getGatewayId(), service);
             dispatcher = new GSMDispatcher(service , smsInManeger);
             dispatcher.setPollInterval(gsmTransportInDetails.getModemPollInterval());
             Thread thread = new Thread(dispatcher);
@@ -99,6 +105,14 @@
         try {
             dispatcher.stopPolling();
             service.stopService();
+            if(serviceRepo.gatewayInUse(gsmTransportInDetails.getGatewayId())) {
+                serviceRepo.removeService(gsmTransportInDetails.getGatewayId());
+            }
+
+            if(serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) {
+                serviceRepo.removeService(gsmTransportOutDetails.getGatewayId());
+            }
+
         } catch (Exception e) {
             log.error(e);
         }
@@ -186,7 +200,7 @@
     }
 
     public void sendSMS(SMSMessage sm) {
-        if (service == null) {
+        if (service == null && !serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) {
             //Operating in the Out Only mode
             service = new Service();
             gateway = new SerialModemGateway(gsmTransportOutDetails.getGatewayId(), gsmTransportOutDetails.getComPort(),
@@ -216,6 +230,8 @@
                 log.error(e);
             }
 
+        } else if(serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) {
+            service = serviceRepo.getService(gsmTransportOutDetails.getGatewayId());    
         }
 
         OutboundMessage msg =  new OutboundMessage(sm.getReceiver(), sm.getContent());

Added: webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMServiceRepository.java
URL: http://svn.apache.org/viewvc/webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMServiceRepository.java?rev=887103&view=auto
==============================================================================
--- webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMServiceRepository.java (added)
+++ webservices/commons/branches/modules/transport/1.0.0/modules/sms/src/main/java/org/apache/axis2/transport/sms/gsm/GSMServiceRepository.java Fri Dec  4 08:22:51 2009
@@ -0,0 +1,87 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF 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 org.apache.axis2.transport.sms.gsm;
+
+import org.smslib.Service;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * The Repository of started GSM Services
+ * Allow to share and reuse the GSM services
+ */
+class GSMServiceRepository {
+
+    private Map<String, Service> serviceRepo = new HashMap<String,Service>();
+
+    private static GSMServiceRepository me;
+
+    private GSMServiceRepository() {
+
+    }
+
+    public static GSMServiceRepository getInstence() {
+        if(me == null) {
+            me = new GSMServiceRepository();
+        }
+
+        return me;
+    }
+
+    /**
+     * add a service with a given gateway
+     * @param gateway
+     * @param service
+     */
+    public void addService(String gateway , Service service) {
+        if(!gatewayInUse(gateway)) {
+            serviceRepo.put(gateway,service);
+        }
+    }
+
+    /**
+     * remove the service given the gateway id
+     * @param gateway
+     */
+    public void removeService(String gateway) {
+        serviceRepo.remove(gateway);
+    }
+   
+
+    /**
+     * get the service given the gateway id
+     * @param gateway
+     * @return
+     */
+    public Service getService(String gateway) {
+        return serviceRepo.get(gateway);
+    }
+
+    /**
+     * to know whether the gateway inuse
+     * @param gateway
+     * @return
+     */
+    public boolean gatewayInUse(String gateway) {
+        return serviceRepo.containsKey(gateway);
+    }
+
+
+}