dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43768
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22191: Eliminated circular dep bw TransportService and SmsPublisher
------------------------------------------------------------
revno: 22191
committer: Zubair Asghar<zubair@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-03-08 15:53:40 +0100
message:
Eliminated circular dep bw TransportService and SmsPublisher
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsConsumerService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/incoming/DefaultSmsConsumerService.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java 2016-02-23 03:31:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java 2016-03-08 14:53:40 +0000
@@ -71,6 +71,7 @@
INSTANCE_BASE_URL( "keyInstanceBaseUrl" ),
SCHEDULED_TASKS( "keySchedTasks", ListMap.class ),
SMS_CONFIG( "keySmsConfig", SmsConfiguration.class ),
+ SMS_CONSUMER_STATE( "isStarted", Boolean.FALSE, Boolean.class ),
CACHE_STRATEGY( "keyCacheStrategy", "CACHE_6AM_TOMORROW", String.class ),
PHONE_NUMBER_AREA_CODE( "phoneNumberAreaCode" ),
MULTI_ORGANISATION_UNIT_FORMS( "multiOrganisationUnitForms", Boolean.FALSE, Boolean.class ),
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsConsumerService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsConsumerService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/incoming/SmsConsumerService.java 2016-03-08 14:53:40 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.sms.incoming;
+
+
+/*
+ * Copyright (c) 2004-2016, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+public interface SmsConsumerService
+{
+ void startSmsConsumer();
+ void stopSmsConsumer();
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java 2016-01-04 14:50:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/SmsPublisher.java 2016-03-08 14:53:40 +0000
@@ -37,7 +37,6 @@
public class SmsPublisher
{
- private static final Log log = LogFactory.getLog( SmsPublisher.class );
@Autowired
private MessageQueue messageQueue;
@@ -61,13 +60,10 @@
smsConsumer.spawnSmsConsumer();
}
}, 5000 );
-
- log.info( "SMS Consumer Started" );
}
public void stop()
{
future.cancel( true );
- log.info( "SMS Consumer Stopped" );
}
}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/incoming/DefaultSmsConsumerService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/incoming/DefaultSmsConsumerService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/incoming/DefaultSmsConsumerService.java 2016-03-08 14:53:40 +0000
@@ -0,0 +1,98 @@
+package org.hisp.dhis.sms.incoming;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.setting.SettingKey;
+import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.sms.SmsPublisher;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+
+/*
+ * Copyright (c) 2004-2016, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+public class DefaultSmsConsumerService
+ implements ApplicationListener<ContextRefreshedEvent>, SmsConsumerService
+{
+ private static final Log log = LogFactory.getLog( DefaultSmsConsumerService.class );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private SystemSettingManager systemSettingManager;
+
+ @Autowired
+ private SmsPublisher smsPublisher;
+
+ // -------------------------------------------------------------------------
+ // Implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void startSmsConsumer()
+ {
+ smsPublisher.start();
+
+ log.info( "SMS Consumer Stared" );
+
+ saveSmsConsumerState( true );
+ }
+
+ @Override
+ public void stopSmsConsumer()
+ {
+ smsPublisher.stop();
+
+ log.info( "SMS Consumer Stopped !!! " );
+
+ saveSmsConsumerState( false );
+ }
+
+ @Override
+ public void onApplicationEvent( ContextRefreshedEvent event )
+ {
+ if ( getSmsConsumerState() )
+ {
+ startSmsConsumer();
+ }
+ }
+
+ private boolean getSmsConsumerState()
+ {
+ return (boolean) systemSettingManager.getSystemSetting( SettingKey.SMS_CONSUMER_STATE );
+ }
+
+ private void saveSmsConsumerState( boolean state )
+ {
+ systemSettingManager.saveSystemSetting( SettingKey.SMS_CONSUMER_STATE, state );
+ }
+
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java 2016-03-07 16:08:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/outbound/DefaultOutboundSmsTransportService.java 2016-03-08 14:53:40 +0000
@@ -94,12 +94,12 @@
this.outboundSmsService = outboundSmsService;
}
- private SmsPublisher smsPublisher;
-
- public void setSmsPublisher( SmsPublisher smsPublisher )
- {
- this.smsPublisher = smsPublisher;
- }
+// private SmsPublisher smsPublisher;
+//
+// public void setSmsPublisher( SmsPublisher smsPublisher )
+// {
+// this.smsPublisher = smsPublisher;
+// }
// -------------------------------------------------------------------------
// OutboundSmsTransportService implementation
@@ -129,7 +129,7 @@
try
{
getService().stopService();
- smsPublisher.stop();
+ // smsPublisher.stop();
}
catch ( SMSLibException e )
{
@@ -165,7 +165,7 @@
try
{
- smsPublisher.start();
+ // smsPublisher.start();
}
catch ( Exception e1 )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2016-03-08 09:18:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2016-03-08 14:53:40 +0000
@@ -1101,6 +1101,10 @@
<bean id="org.hisp.dhis.sms.SmsPublisher" class="org.hisp.dhis.sms.SmsPublisher" />
<bean id="org.hisp.dhis.sms.config.SmsConfigurationManager" class="org.hisp.dhis.sms.config.DefaultSmsConfigurationManager" />
+
+ <bean id="org.hisp.dhis.sms.incoming.SmsConsumerService" class="org.hisp.dhis.sms.incoming.DefaultSmsConsumerService" />
+
+
<bean id="org.hisp.dhis.sms.incoming.IncomingSmsService" class="org.hisp.dhis.sms.incoming.DefaultIncomingSmsService">
<property name="incomingSmsStore" ref="org.hisp.dhis.sms.hibernate.IncomingSmsStore" />
@@ -1119,7 +1123,6 @@
<property name="smppInboundMessageNotification" ref="org.smslib.IInboundMessageNotification" />
<property name="outboundMessageNotification" ref="org.smslib.IOutboundMessageNotification" />
<property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
- <property name="smsPublisher" ref="org.hisp.dhis.sms.SmsPublisher" />
</bean>
<bean id="org.hisp.dhis.sms.SmsSender" class="org.hisp.dhis.sms.DefaultSmsSender" />
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/ReloadStartStopServiceAction.java 2016-03-08 14:53:40 +0000
@@ -30,6 +30,7 @@
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.sms.config.SmsConfigurationManager;
+import org.hisp.dhis.sms.incoming.SmsConsumerService;
import org.hisp.dhis.sms.outbound.OutboundSmsTransportService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,6 +53,9 @@
@Autowired
private OutboundSmsTransportService outboundSmsTransportService;
+
+ @Autowired
+ private SmsConsumerService smsConsumerService;
// -------------------------------------------------------------------------
// Input & Output
@@ -100,10 +104,14 @@
if ( actionType != null && actionType.equals( "start" ) )
{
outboundSmsTransportService.startService();
+
+ smsConsumerService.startSmsConsumer();
}
else if ( actionType.equals( "stop" ) )
{
outboundSmsTransportService.stopService();
+
+ smsConsumerService.stopSmsConsumer();
}
else
{