diff --git a/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java b/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java index 475cb295af..594743871a 100644 --- a/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java +++ b/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java @@ -78,7 +78,7 @@ private MediaServerControllerFactory mediaServerControllerFactory(final Configur try { settings = configuration.subset("media-server-manager"); ActorRef mrb = mediaResourceBroker(settings, storage, loader); - factory = new MmsControllerFactory(system, mrb); + factory = new MmsControllerFactory(mrb); } catch (UnknownHostException e) { throw new ServletException(e); } @@ -98,7 +98,7 @@ private MediaServerControllerFactory mediaServerControllerFactory(final Configur // Create JSR 309 factory MsControlFactory msControlFactory = driver.getFactory(properties); MediaServerInfo mediaServerInfo = mediaServerInfo(settings); - factory = new Jsr309ControllerFactory(system, mediaServerInfo, msControlFactory); + factory = new Jsr309ControllerFactory(mediaServerInfo, msControlFactory); } catch (UnknownHostException | MsControlException e) { throw new ServletException(e); } diff --git a/restcomm/restcomm.asr/src/main/java/org/restcomm/connect/asr/ISpeechAsr.java b/restcomm/restcomm.asr/src/main/java/org/restcomm/connect/asr/ISpeechAsr.java index bbd32cd10d..4473ea2736 100644 --- a/restcomm/restcomm.asr/src/main/java/org/restcomm/connect/asr/ISpeechAsr.java +++ b/restcomm/restcomm.asr/src/main/java/org/restcomm/connect/asr/ISpeechAsr.java @@ -20,23 +20,22 @@ package org.restcomm.connect.asr; import akka.actor.ActorRef; -import akka.actor.UntypedActor; - import com.iSpeech.SpeechResult; import com.iSpeech.iSpeechRecognizer; -import static com.iSpeech.iSpeechRecognizer.*; import com.iSpeech.iSpeechRecognizer.SpeechRecognizerEvent; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import java.io.File; import java.util.HashMap; import java.util.Map; -import org.apache.commons.configuration.Configuration; +import static com.iSpeech.iSpeechRecognizer.FREEFORM_DICTATION; /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class ISpeechAsr extends UntypedActor implements SpeechRecognizerEvent { +public final class ISpeechAsr extends RestcommUntypedActor implements SpeechRecognizerEvent { private static final Map languages = new HashMap(); static { languages.put("en", "en-US"); diff --git a/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/cache/DiskCache.java b/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/cache/DiskCache.java index fffd6cfcad..b3f739dc0d 100644 --- a/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/cache/DiskCache.java +++ b/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/cache/DiskCache.java @@ -20,12 +20,12 @@ package org.restcomm.connect.commons.cache; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.shiro.crypto.hash.Sha256Hash; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import java.io.File; import java.io.FileNotFoundException; @@ -39,7 +39,7 @@ /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class DiskCache extends UntypedActor { +public final class DiskCache extends RestcommUntypedActor { // Logger. private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); diff --git a/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/faulttolerance/RestcommSupervisorStrategy.java b/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/faulttolerance/RestcommSupervisorStrategy.java index 746c1c642f..56c783b190 100644 --- a/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/faulttolerance/RestcommSupervisorStrategy.java +++ b/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/faulttolerance/RestcommSupervisorStrategy.java @@ -20,9 +20,9 @@ public class RestcommSupervisorStrategy implements SupervisorStrategyConfigurato private static Logger logger = Logger.getLogger(RestcommSupervisorStrategy.class); - final SupervisorStrategy.Directive strategy = resume(); + static final SupervisorStrategy.Directive strategy = resume(); - RestcommFaultToleranceStrategy defaultStrategy = new RestcommFaultToleranceStrategy(10, Duration.create("1 minute"), + static RestcommFaultToleranceStrategy defaultStrategy = new RestcommFaultToleranceStrategy(10, Duration.create("1 minute"), new RestcommFaultToleranceDecider()); @Override @@ -30,7 +30,11 @@ public SupervisorStrategy create() { return defaultStrategy; } - private class RestcommFaultToleranceStrategy extends OneForOneStrategy { + public static SupervisorStrategy getStrategy() { + return defaultStrategy; + } + + private static class RestcommFaultToleranceStrategy extends OneForOneStrategy { public RestcommFaultToleranceStrategy(int maxNrOfRetries, Duration withinTimeRange, Function function) { super(maxNrOfRetries, withinTimeRange, function); @@ -51,7 +55,7 @@ public boolean handleFailure(ActorContext context, ActorRef child, Throwable cau // } } - private class RestcommFaultToleranceDecider implements Function { + private static class RestcommFaultToleranceDecider implements Function { @Override // - 2nd the Supervisor strategy will execute the Decider apply() to check what to do with the exception diff --git a/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/faulttolerance/RestcommUntypedActor.java b/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/faulttolerance/RestcommUntypedActor.java new file mode 100644 index 0000000000..559b33e6d8 --- /dev/null +++ b/restcomm/restcomm.commons/src/main/java/org/restcomm/connect/commons/faulttolerance/RestcommUntypedActor.java @@ -0,0 +1,35 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +package org.restcomm.connect.commons.faulttolerance; + +import akka.actor.SupervisorStrategy; +import akka.actor.UntypedActor; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public abstract class RestcommUntypedActor extends UntypedActor { + + @Override + public SupervisorStrategy supervisorStrategy() { + return RestcommSupervisorStrategy.getStrategy(); + } +} diff --git a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/SupervisorActorCreationStressTest.java b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/SupervisorActorCreationStressTest.java index c5a4a09001..cede0393c6 100644 --- a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/SupervisorActorCreationStressTest.java +++ b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/SupervisorActorCreationStressTest.java @@ -16,9 +16,7 @@ import org.junit.Test; import org.restcomm.connect.commons.faulttolerance.tool.ActorCreatingThread; -import akka.actor.ActorRef; import akka.actor.ActorSystem; -import akka.actor.Props; /** * @author mariafarooq @@ -46,7 +44,7 @@ public static void beforeClass() throws Exception { actorFailureCount = new AtomicInteger(); } - @Test + @Test public void testCreateSampleAkkaActor() throws ConfigurationException, MalformedURLException, UnknownHostException, InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(nThreads); for (int i = 0; i < THREAD_COUNT; i++) { diff --git a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/MyUntypedActor.java b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/MyUntypedActor.java index 098e8404dc..22e018a867 100644 --- a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/MyUntypedActor.java +++ b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/MyUntypedActor.java @@ -1,20 +1,14 @@ package org.restcomm.connect.commons.faulttolerance.tool; -import static akka.pattern.Patterns.ask; - -import java.util.concurrent.TimeUnit; - -import akka.actor.ActorSystem; -import org.restcomm.connect.commons.faulttolerance.SupervisorActorCreationStressTest; - import akka.actor.ActorRef; +import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; -import scala.concurrent.Await; -import scala.concurrent.duration.Duration; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.commons.faulttolerance.SupervisorActorCreationStressTest; /** * MyUntypedActor represent a restcomm-connect class that request supervisor to create actor for it @@ -22,7 +16,7 @@ * @author mariafarooq * */ -public class MyUntypedActor extends UntypedActor { +public class MyUntypedActor extends RestcommUntypedActor { private LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private final ActorSystem system; diff --git a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/SimpleActor.java b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/SimpleActor.java index 352f75b1be..d126731961 100644 --- a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/SimpleActor.java +++ b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/faulttolerance/tool/SimpleActor.java @@ -1,6 +1,6 @@ package org.restcomm.connect.commons.faulttolerance.tool; -import akka.actor.UntypedActor; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; /** * SampleActor: a simple actor to be created @@ -8,7 +8,7 @@ * @author mariafarooq * */ -public class SimpleActor extends UntypedActor { +public class SimpleActor extends RestcommUntypedActor { public SimpleActor(){ } diff --git a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/patterns/ObserverPatternTest.java b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/patterns/ObserverPatternTest.java index eb5f4f449a..1f60838767 100644 --- a/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/patterns/ObserverPatternTest.java +++ b/restcomm/restcomm.commons/src/test/java/org/restcomm/connect/commons/patterns/ObserverPatternTest.java @@ -22,20 +22,17 @@ import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Props; -import akka.actor.UntypedActor; import akka.testkit.JavaTestKit; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.*; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.Observing; -import org.restcomm.connect.commons.patterns.StopObserving; -import org.restcomm.connect.commons.patterns.TooManyObserversException; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author thomas.quintana@telestax.com (Thomas Quintana) @@ -108,7 +105,7 @@ public void testTooManyObserversException() { private static final class BroadcastHelloWorld { } - private static final class ObservableActor extends UntypedActor { + private static final class ObservableActor extends RestcommUntypedActor { private final List listeners; @SuppressWarnings("unused") diff --git a/restcomm/restcomm.email/src/main/java/org/restcomm/connect/email/EmailService.java b/restcomm/restcomm.email/src/main/java/org/restcomm/connect/email/EmailService.java index 73dde39d59..3dc8a186b1 100644 --- a/restcomm/restcomm.email/src/main/java/org/restcomm/connect/email/EmailService.java +++ b/restcomm/restcomm.email/src/main/java/org/restcomm/connect/email/EmailService.java @@ -20,19 +20,20 @@ package org.restcomm.connect.email; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import org.apache.commons.configuration.Configuration; -import org.restcomm.connect.email.api.EmailRequest; -import org.restcomm.connect.email.api.EmailResponse; -import org.restcomm.connect.email.api.Mail; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.patterns.Observe; import org.restcomm.connect.commons.patterns.Observing; import org.restcomm.connect.commons.patterns.StopObserving; +import org.restcomm.connect.email.api.EmailRequest; +import org.restcomm.connect.email.api.EmailResponse; +import org.restcomm.connect.email.api.Mail; import javax.mail.Message; import javax.mail.MessagingException; +import javax.mail.NoSuchProviderException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; @@ -41,13 +42,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import javax.mail.NoSuchProviderException; /** * @author liblefty@gmail.com (Lefteris Banos) */ -public class EmailService extends UntypedActor { +public class EmailService extends RestcommUntypedActor { final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private final List observers; diff --git a/restcomm/restcomm.fax/src/main/java/org/restcomm/connect/fax/InterfaxService.java b/restcomm/restcomm.fax/src/main/java/org/restcomm/connect/fax/InterfaxService.java index 8f434cfbb9..0a320b3753 100644 --- a/restcomm/restcomm.fax/src/main/java/org/restcomm/connect/fax/InterfaxService.java +++ b/restcomm/restcomm.fax/src/main/java/org/restcomm/connect/fax/InterfaxService.java @@ -20,14 +20,6 @@ package org.restcomm.connect.fax; import akka.actor.ActorRef; -import akka.actor.UntypedActor; - -import java.io.File; -import java.net.URI; -import java.net.URLConnection; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; - import org.apache.commons.configuration.Configuration; import org.apache.http.Header; import org.apache.http.HttpHeaders; @@ -45,11 +37,18 @@ import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; + +import java.io.File; +import java.net.URI; +import java.net.URLConnection; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class InterfaxService extends UntypedActor { +public final class InterfaxService extends RestcommUntypedActor { private static final String url = "https://rest.interfax.net/outbound/faxes?faxNumber="; private final TrustStrategy strategy; diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java index 4ced8a1fda..b876c8c1df 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java @@ -62,13 +62,8 @@ import java.util.ArrayList; import java.util.List; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; -import static javax.ws.rs.core.MediaType.APPLICATION_XML; -import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE; -import static javax.ws.rs.core.Response.Status.BAD_REQUEST; -import static javax.ws.rs.core.Response.Status.CONFLICT; -import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.MediaType.*; +import static javax.ws.rs.core.Response.Status.*; import static javax.ws.rs.core.Response.ok; import static javax.ws.rs.core.Response.status; diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/EmailMessagesEndpoint.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/EmailMessagesEndpoint.java index 0fd3f66959..2d7a13ac35 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/EmailMessagesEndpoint.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/EmailMessagesEndpoint.java @@ -13,6 +13,7 @@ import org.apache.commons.configuration.Configuration; import org.apache.log4j.Logger; import org.joda.time.DateTime; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.patterns.Observe; import org.restcomm.connect.commons.patterns.Observing; import org.restcomm.connect.commons.patterns.StopObserving; @@ -33,10 +34,7 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; -import static javax.ws.rs.core.MediaType.APPLICATION_XML; -import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE; +import static javax.ws.rs.core.MediaType.*; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; import static javax.ws.rs.core.Response.ok; @@ -241,7 +239,7 @@ public UntypedActor create() throws Exception { return system.actorOf(props); } - private final class EmailSessionObserver extends UntypedActor { + private final class EmailSessionObserver extends RestcommUntypedActor { public EmailSessionObserver() { super(); } diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SmsMessagesEndpoint.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SmsMessagesEndpoint.java index 890352d20a..de7b32fe18 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SmsMessagesEndpoint.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SmsMessagesEndpoint.java @@ -37,6 +37,7 @@ import org.restcomm.connect.commons.annotations.concurrency.NotThreadSafe; import org.restcomm.connect.commons.configuration.RestcommConfiguration; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.patterns.Observe; import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.dao.SmsMessagesDao; @@ -77,13 +78,8 @@ import java.util.concurrent.TimeUnit; import static akka.pattern.Patterns.ask; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; -import static javax.ws.rs.core.MediaType.APPLICATION_XML; -import static javax.ws.rs.core.MediaType.APPLICATION_XML_TYPE; -import static javax.ws.rs.core.Response.Status.BAD_REQUEST; -import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; -import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.MediaType.*; +import static javax.ws.rs.core.Response.Status.*; import static javax.ws.rs.core.Response.ok; import static javax.ws.rs.core.Response.status; @@ -391,7 +387,7 @@ public UntypedActor create() throws Exception { return system.actorOf(props); } - private final class SmsSessionObserver extends UntypedActor { + private final class SmsSessionObserver extends RestcommUntypedActor { public SmsSessionObserver() { super(); } diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/client/Downloader.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/client/Downloader.java index f8ca634fc3..6d4d70ec47 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/client/Downloader.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/client/Downloader.java @@ -20,7 +20,6 @@ package org.restcomm.connect.http.client; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import org.apache.http.Header; @@ -38,8 +37,9 @@ import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.client.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; -import org.restcomm.connect.commons.configuration.RestcommConfiguration; import org.restcomm.connect.commons.common.http.CustomHttpClientBuilder; +import org.restcomm.connect.commons.configuration.RestcommConfiguration; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.StringUtils; import org.xml.sax.InputSource; @@ -57,7 +57,7 @@ /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class Downloader extends UntypedActor { +public final class Downloader extends RestcommUntypedActor { public static final int LOGGED_RESPONSE_MAX_SIZE = 100; diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/AudioPlayerInterpreter.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/AudioPlayerInterpreter.java index 758cf9c900..14284931f5 100644 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/AudioPlayerInterpreter.java +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/AudioPlayerInterpreter.java @@ -19,12 +19,12 @@ */ package org.restcomm.connect.interpreter; -import akka.actor.UntypedActor; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class AudioPlayerInterpreter extends UntypedActor { +public final class AudioPlayerInterpreter extends RestcommUntypedActor { public AudioPlayerInterpreter() { super(); } diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/BaseVoiceInterpreter.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/BaseVoiceInterpreter.java index 81f3eb3ff9..7d3a276971 100644 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/BaseVoiceInterpreter.java +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/BaseVoiceInterpreter.java @@ -21,7 +21,6 @@ import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; @@ -47,6 +46,7 @@ import org.restcomm.connect.commons.cache.DiskCacheResponse; import org.restcomm.connect.commons.cache.HashGenerator; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -131,7 +131,7 @@ * @author gvagenas@telestax.com * @author pavel.slegr@telestax.com */ -public abstract class BaseVoiceInterpreter extends UntypedActor { +public abstract class BaseVoiceInterpreter extends RestcommUntypedActor { // Logger. private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); @@ -140,8 +140,6 @@ public abstract class BaseVoiceInterpreter extends UntypedActor { static final Pattern PATTERN = Pattern.compile("[\\*#0-9]{1,12}"); static String EMAIL_SENDER = "restcomm@restcomm.org"; - protected final ActorSystem system; - // States for the FSM. // ========================== final State uninitialized; @@ -260,7 +258,6 @@ public abstract class BaseVoiceInterpreter extends UntypedActor { public BaseVoiceInterpreter() { super(); final ActorRef source = self(); - this.system = context().system(); // 20 States in common uninitialized = new State("uninitialized", null, null); acquiringAsrInfo = new State("acquiring asr info", new AcquiringAsrInfo(source), null); @@ -418,7 +415,7 @@ public Actor create() throws Exception { return new ISpeechAsr(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } @SuppressWarnings("unchecked") @@ -467,7 +464,7 @@ public Actor create() throws Exception { return new InterfaxService(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } //Callback using the Akka ask pattern (http://doc.akka.io/docs/akka/2.2.5/java/untyped-actors.html#Ask__Send-And-Receive-Future) will force VoiceInterpter to wait until @@ -536,7 +533,7 @@ public UntypedActor create() throws Exception { return new DiskCacheFactory(configuration).getDiskCache(path, uri); } }); - return system.actorOf(props); + return getContext().actorOf(props); } ActorRef downloader() { @@ -548,7 +545,7 @@ public UntypedActor create() throws Exception { return new Downloader(); } }); - return system.actorOf(props); + return getContext().actorOf(props); } String e164(final String number) { @@ -581,7 +578,7 @@ public Actor create() throws Exception { return new EmailService(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private Notification notification(final int log, final int error, final String message) { @@ -646,18 +643,18 @@ public UntypedActor create() throws IOException { return new Parser(xml, self()); } }); - return system.actorOf(props); + return getContext().actorOf(props); } void postCleanup() { if (smsSessions.isEmpty() && outstandingAsrRequests == 0) { final UntypedActorContext context = getContext(); if (parser != null) - system.stop(parser); + getContext().stop(parser); context.stop(self()); } if (downloader != null && !downloader.isTerminated()) { - system.stop(downloader); + getContext().stop(downloader); } } @@ -815,7 +812,7 @@ public Actor create() throws Exception { return (UntypedActor) Class.forName(classpath).getConstructor(Configuration.class).newInstance(ttsConf); } }); - return system.actorOf(props); + return getContext().actorOf(props); } abstract class AbstractAction implements Action { diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreter.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreter.java index cc204935c9..3ab740f54e 100644 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreter.java +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreter.java @@ -2,7 +2,6 @@ import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.ReceiveTimeout; import akka.actor.UntypedActor; @@ -24,6 +23,7 @@ import org.restcomm.connect.commons.cache.DiskCacheResponse; import org.restcomm.connect.commons.cache.HashGenerator; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -73,7 +73,7 @@ import static org.restcomm.connect.interpreter.rcml.Verbs.play; import static org.restcomm.connect.interpreter.rcml.Verbs.say; -public class ConfVoiceInterpreter extends UntypedActor { +public class ConfVoiceInterpreter extends RestcommUntypedActor { private static final int ERROR_NOTIFICATION = 0; private static final int WARNING_NOTIFICATION = 1; static String EMAIL_SENDER; @@ -146,15 +146,10 @@ public class ConfVoiceInterpreter extends UntypedActor { private ActorRef originalInterpreter; - private ActorSystem system; - - public ConfVoiceInterpreter(final Configuration configuration, final Sid account, final String version, final URI url, - final String method, final String emailAddress, final ActorRef conference, final DaoManager storage, - final CallInfo callInfo) { + public ConfVoiceInterpreter(final ConfVoiceInterpreterParams params) { super(); - this.system = context().system(); source = self(); uninitialized = new State("uninitialized", null, null); @@ -233,14 +228,14 @@ public ConfVoiceInterpreter(final Configuration configuration, final Sid account // Initialize the FSM. this.fsm = new FiniteStateMachine(uninitialized, transitions); // Initialize the runtime stuff. - this.accountId = account; - this.version = version; - this.url = url; - this.method = method; - this.emailAddress = emailAddress; - this.configuration = configuration; - - this.storage = storage; + this.accountId = params.getAccount(); + this.version = params.getVersion(); + this.url = params.getUrl(); + this.method = params.getMethod(); + this.emailAddress = params.getEmailAddress(); + this.configuration = params.getConfiguration(); + + this.storage = params.getStorage(); this.synthesizer = tts(configuration.subset("speech-synthesizer")); final Configuration runtime = configuration.subset("runtime-settings"); String path = runtime.getString("cache-path"); @@ -257,8 +252,17 @@ public ConfVoiceInterpreter(final Configuration configuration, final Sid account this.cache = cache(path, uri); this.downloader = downloader(); - this.callInfo = callInfo; - this.conference = conference; + this.callInfo = params.getCallInfo(); + this.conference = params.getConference(); + } + + public static Props props(final ConfVoiceInterpreterParams params) { + return new Props(new UntypedActorFactory() { + @Override + public Actor create() throws Exception { + return new ConfVoiceInterpreter(params); + } + }); } private ActorRef cache(final String path, final String uri) { @@ -270,7 +274,7 @@ public UntypedActor create() throws Exception { return new DiskCacheFactory(configuration).getDiskCache(path, uri); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private ActorRef downloader() { @@ -282,7 +286,7 @@ public UntypedActor create() throws Exception { return new Downloader(); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private String e164(final String number) { @@ -311,7 +315,7 @@ public Actor create() throws Exception { return new EmailService(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private Notification notification(final int log, final int error, final String message) { @@ -510,7 +514,7 @@ public UntypedActor create() throws Exception { return new Parser(xml, self()); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private void postCleanup() { @@ -584,7 +588,7 @@ public Actor create() throws Exception { return (UntypedActor) Class.forName(classpath).getConstructor(Configuration.class).newInstance(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private abstract class AbstractAction implements Action { diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreterBuilder.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreterBuilder.java deleted file mode 100644 index 20467fcc14..0000000000 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreterBuilder.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.restcomm.connect.interpreter; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorFactory; -import org.apache.commons.configuration.Configuration; -import org.apache.log4j.Logger; -import org.restcomm.connect.commons.dao.Sid; -import org.restcomm.connect.dao.DaoManager; -import org.restcomm.connect.telephony.api.CallInfo; - -import java.net.URI; - -public class ConfVoiceInterpreterBuilder { - - private Logger logger = Logger.getLogger(ConfVoiceInterpreterBuilder.class); - private ActorSystem system; - private Configuration configuration; - private Sid account; - private String version; - private URI url; - private String method; - private String emailAddress; - private ActorRef conference; - private DaoManager storage; - private CallInfo callInfo; - - public ConfVoiceInterpreterBuilder(final ActorSystem system) { - super(); - this.system = system; - } - - public ActorRef build() { - final Props props = new Props(new UntypedActorFactory() { - private static final long serialVersionUID = 1L; - @Override - public UntypedActor create() throws Exception { - return new ConfVoiceInterpreter(configuration, account, version, url, method, emailAddress, conference, - storage, callInfo); - } - }); - return system.actorOf(props); - } - - public void setConfiguration(final Configuration configuration) { - this.configuration = configuration; - } - - public void setAccount(final Sid account) { - this.account = account; - } - - public void setVersion(final String version) { - this.version = version; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public void setMethod(final String method) { - this.method = method; - } - - public void setEmailAddress(final String emailAddress) { - this.emailAddress = emailAddress; - } - - public void setConference(final ActorRef conference) { - this.conference = conference; - } - - public void setStorage(final DaoManager storage) { - this.storage = storage; - } - - public void setCallInfo(CallInfo callInfo) { - this.callInfo = callInfo; - } - -} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreterParams.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreterParams.java new file mode 100644 index 0000000000..8c492a921b --- /dev/null +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/ConfVoiceInterpreterParams.java @@ -0,0 +1,154 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +package org.restcomm.connect.interpreter; + +import akka.actor.ActorRef; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.dao.DaoManager; +import org.restcomm.connect.telephony.api.CallInfo; + +import java.net.URI; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public final class ConfVoiceInterpreterParams { + + private Configuration configuration; + private Sid account; + private String version; + private URI url; + private String method; + private String emailAddress; + private ActorRef conference; + private DaoManager storage; + private CallInfo callInfo; + + private ConfVoiceInterpreterParams(Configuration configuration, Sid account, String version, URI url, String method, String emailAddress, ActorRef conference, DaoManager storage, CallInfo callInfo) { + this.configuration = configuration; + this.account = account; + this.version = version; + this.url = url; + this.method = method; + this.emailAddress = emailAddress; + this.conference = conference; + this.storage = storage; + this.callInfo = callInfo; + } + + public Configuration getConfiguration() { + return configuration; + } + + public Sid getAccount() { + return account; + } + + public String getVersion() { + return version; + } + + public URI getUrl() { + return url; + } + + public String getMethod() { + return method; + } + + public String getEmailAddress() { + return emailAddress; + } + + public ActorRef getConference() { + return conference; + } + + public DaoManager getStorage() { + return storage; + } + + public CallInfo getCallInfo() { + return callInfo; + } + + public static class ConfVoiceInterpreterParamsBuilder { + private Configuration configuration; + private Sid account; + private String version; + private URI url; + private String method; + private String emailAddress; + private ActorRef conference; + private DaoManager storage; + private CallInfo callInfo; + + public ConfVoiceInterpreterParamsBuilder setConfiguration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setAccount(Sid account) { + this.account = account; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setVersion(String version) { + this.version = version; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setUrl(URI url) { + this.url = url; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setMethod(String method) { + this.method = method; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setConference(ActorRef conference) { + this.conference = conference; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setStorage(DaoManager storage) { + this.storage = storage; + return this; + } + + public ConfVoiceInterpreterParamsBuilder setCallInfo(CallInfo callInfo) { + this.callInfo = callInfo; + return this; + } + + public ConfVoiceInterpreterParams biuld() { + return new ConfVoiceInterpreterParams(configuration, account, version, url, method, emailAddress, conference, storage, callInfo); + } + } +} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreter.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreter.java index fde93038a9..d43da8647f 100644 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreter.java +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreter.java @@ -21,7 +21,6 @@ import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; @@ -40,6 +39,7 @@ import org.apache.http.message.BasicNameValuePair; import org.joda.time.DateTime; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -92,14 +92,13 @@ /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class SmsInterpreter extends UntypedActor { +public final class SmsInterpreter extends RestcommUntypedActor { private static final int ERROR_NOTIFICATION = 0; private static final int WARNING_NOTIFICATION = 1; static String EMAIL_SENDER; // Logger private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - private final ActorSystem system; // States for the FSM. private final State uninitialized; private final State acquiringLastSmsRequest; @@ -149,12 +148,9 @@ public final class SmsInterpreter extends UntypedActor { private ConcurrentHashMap customHttpHeaderMap = new ConcurrentHashMap(); private ConcurrentHashMap customRequestHeaderMap; - public SmsInterpreter(final ActorRef service, final Configuration configuration, final DaoManager storage, - final Sid accountId, final String version, final URI url, final String method, final URI fallbackUrl, - final String fallbackMethod) { + public SmsInterpreter(final SmsInterpreterParams params) { super(); final ActorRef source = self(); - this.system = context().system(); uninitialized = new State("uninitialized", null, null); acquiringLastSmsRequest = new State("acquiring last sms event", new AcquiringLastSmsEvent(source), null); downloadingRcml = new State("downloading rcml", new DownloadingRcml(source), null); @@ -210,22 +206,31 @@ public SmsInterpreter(final ActorRef service, final Configuration configuration, // Initialize the FSM. this.fsm = new FiniteStateMachine(uninitialized, transitions); // Initialize the runtime stuff. - this.service = service; + this.service = params.getSmsService(); this.downloader = downloader(); - this.storage = storage; - this.emailconfiguration = configuration.subset("smtp-service"); - this.runtime = configuration.subset("runtime-settings"); - this.configuration = configuration.subset("sms-aggregator"); - this.accountId = accountId; - this.version = version; - this.url = url; - this.method = method; - this.fallbackUrl = fallbackUrl; - this.fallbackMethod = fallbackMethod; + this.storage = params.getStorage(); + this.emailconfiguration = params.getConfiguration().subset("smtp-service"); + this.runtime = params.getConfiguration().subset("runtime-settings"); + this.configuration = params.getConfiguration().subset("sms-aggregator"); + this.accountId = params.getAccountId(); + this.version = params.getVersion(); + this.url = params.getUrl(); + this.method = params.getMethod(); + this.fallbackUrl = params.getFallbackUrl(); + this.fallbackMethod = params.getFallbackMethod(); this.sessions = new HashMap(); this.normalizeNumber = runtime.getBoolean("normalize-numbers-for-outbound-calls"); } + public static Props props(final SmsInterpreterParams params) { + return new Props(new UntypedActorFactory() { + @Override + public Actor create() throws Exception { + return new SmsInterpreter(params); + } + }); + } + private ActorRef downloader() { final Props props = new Props(new UntypedActorFactory() { private static final long serialVersionUID = 1L; @@ -235,7 +240,7 @@ public UntypedActor create() throws Exception { return new Downloader(); } }); - return system.actorOf(props); + return getContext().actorOf(props); } ActorRef mailer(final Configuration configuration) { @@ -247,7 +252,7 @@ public Actor create() throws Exception { return new EmailService(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } protected String format(final String number) { @@ -444,7 +449,7 @@ public UntypedActor create() throws Exception { return new Parser(xml, self()); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private void response(final Object message) { diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreterBuilder.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreterBuilder.java deleted file mode 100644 index 2a30bc37a3..0000000000 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreterBuilder.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * TeleStax, Open Source Cloud Communications - * Copyright 2011-2014, Telestax Inc and individual contributors - * by the @authors tag. - * - * This program is free software: you can redistribute it and/or modify - * under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation; either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * - */ -package org.restcomm.connect.interpreter; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorFactory; -import org.apache.commons.configuration.Configuration; -import org.apache.log4j.Logger; -import org.restcomm.connect.commons.dao.Sid; -import org.restcomm.connect.dao.DaoManager; - -import java.net.URI; - -/** - * @author quintana.thomas@gmail.com (Thomas Quintana) - */ -public final class SmsInterpreterBuilder { - private static Logger logger = Logger.getLogger(SmsInterpreterBuilder.class); - private final ActorSystem system; - private Configuration configuration; - private ActorRef service; - private DaoManager storage; - private Sid accountId; - private String version; - private URI url; - private String method; - private URI fallbackUrl; - private String fallbackMethod; - - public SmsInterpreterBuilder(final ActorSystem system) { - super(); - this.system = system; - } - - public ActorRef build() { - final Props props = new Props(new UntypedActorFactory() { - private static final long serialVersionUID = 1L; - - @Override - public UntypedActor create() throws Exception { - return new SmsInterpreter(service, configuration, storage, accountId, version, url, method, fallbackUrl, - fallbackMethod); - } - }); - return system.actorOf(props); - } - - public void setConfiguration(final Configuration configuration) { - this.configuration = configuration; - } - - public void setSmsService(final ActorRef service) { - this.service = service; - } - - public void setStorage(final DaoManager storage) { - this.storage = storage; - } - - public void setAccount(final Sid accountId) { - this.accountId = accountId; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public void setMethod(final String method) { - this.method = method; - } - - public void setFallbackUrl(final URI fallbackUrl) { - this.fallbackUrl = fallbackUrl; - } - - public void setFallbackMethod(final String fallbackMethod) { - this.fallbackMethod = fallbackMethod; - } - - public void setVersion(final String version) { - this.version = version; - } -} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreterParams.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreterParams.java new file mode 100644 index 0000000000..fce4827df8 --- /dev/null +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SmsInterpreterParams.java @@ -0,0 +1,153 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +package org.restcomm.connect.interpreter; + +import akka.actor.ActorRef; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.dao.DaoManager; + +import java.net.URI; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public final class SmsInterpreterParams { + + private Configuration configuration; + private ActorRef smsService; + private DaoManager storage; + private Sid accountId; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + + private SmsInterpreterParams(Configuration configuration, ActorRef smsService, DaoManager storage, Sid accountId, String version, URI url, String method, URI fallbackUrl, String fallbackMethod) { + this.configuration = configuration; + this.smsService = smsService; + this.storage = storage; + this.accountId = accountId; + this.version = version; + this.url = url; + this.method = method; + this.fallbackUrl = fallbackUrl; + this.fallbackMethod = fallbackMethod; + } + + public Configuration getConfiguration() { + return configuration; + } + + public ActorRef getSmsService() { + return smsService; + } + + public DaoManager getStorage() { + return storage; + } + + public Sid getAccountId() { + return accountId; + } + + public String getVersion() { + return version; + } + + public URI getUrl() { + return url; + } + + public String getMethod() { + return method; + } + + public URI getFallbackUrl() { + return fallbackUrl; + } + + public String getFallbackMethod() { + return fallbackMethod; + } + + public static final class Builder { + private Configuration configuration; + private ActorRef smsService; + private DaoManager storage; + private Sid accountId; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + + public Builder setConfiguration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + public Builder setSmsService(ActorRef smsService) { + this.smsService = smsService; + return this; + } + + public Builder setStorage(DaoManager storage) { + this.storage = storage; + return this; + } + + public Builder setAccountId(Sid accountId) { + this.accountId = accountId; + return this; + } + + public Builder setVersion(String version) { + this.version = version; + return this; + } + + public Builder setUrl(URI url) { + this.url = url; + return this; + } + + public Builder setMethod(String method) { + this.method = method; + return this; + } + + public Builder setFallbackUrl(URI fallbackUrl) { + this.fallbackUrl = fallbackUrl; + return this; + } + + public Builder setFallbackMethod(String fallbackMethod) { + this.fallbackMethod = fallbackMethod; + return this; + } + + public SmsInterpreterParams build() { + return new SmsInterpreterParams(configuration, smsService, storage, accountId, version, url, method, fallbackUrl, fallbackMethod); + } + } +} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreter.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreter.java index 6625e2a238..e3b2a69ef2 100644 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreter.java +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreter.java @@ -19,10 +19,12 @@ */ package org.restcomm.connect.interpreter; +import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; +import akka.actor.Props; import akka.actor.ReceiveTimeout; import akka.actor.UntypedActorContext; +import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; @@ -40,7 +42,6 @@ import org.restcomm.connect.commons.fsm.Transition; import org.restcomm.connect.commons.telephony.CreateCallType; import org.restcomm.connect.dao.CallDetailRecordsDao; -import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.dao.NotificationsDao; import org.restcomm.connect.dao.entities.Notification; import org.restcomm.connect.fax.FaxResponse; @@ -95,19 +96,7 @@ public final class SubVoiceInterpreter extends BaseVoiceInterpreter { private Boolean hangupOnEnd = false; private ActorRef originalInterpreter; - public SubVoiceInterpreter(final ActorSystem system, final Configuration configuration, final Sid account, final Sid phone, final String version, - final URI url, final String method, final URI fallbackUrl, final String fallbackMethod, final URI statusCallback, - final String statusCallbackMethod, final String emailAddress, final ActorRef callManager, - final ActorRef conferenceManager, final ActorRef sms, final DaoManager storage) { - - this(configuration, account, phone, version, url, method, fallbackUrl, fallbackMethod, statusCallback, - statusCallbackMethod, emailAddress, callManager, conferenceManager, sms, storage, false); - } - - public SubVoiceInterpreter(final Configuration configuration, final Sid account, final Sid phone, final String version, - final URI url, final String method, final URI fallbackUrl, final String fallbackMethod, final URI statusCallback, - final String statusCallbackMethod, final String emailAddress, final ActorRef callManager, - final ActorRef conferenceManager, final ActorRef sms, final DaoManager storage, final Boolean hangupOnEnd) { + public SubVoiceInterpreter(SubVoiceInterpreterParams params) { super(); source = self(); downloadingRcml = new State("downloading rcml", new DownloadingRcml(source), null); @@ -161,23 +150,23 @@ public SubVoiceInterpreter(final Configuration configuration, final Sid account, // Initialize the FSM. this.fsm = new FiniteStateMachine(uninitialized, transitions); // Initialize the runtime stuff. - this.accountId = account; - this.phoneId = phone; - this.version = version; - this.url = url; - this.method = method; - this.fallbackUrl = fallbackUrl; - this.fallbackMethod = fallbackMethod; - this.viStatusCallback = statusCallback; - this.viStatusCallbackMethod = statusCallbackMethod; - this.emailAddress = emailAddress; - this.configuration = configuration; - this.callManager = callManager; + this.accountId = params.getAccount(); + this.phoneId = params.getPhone(); + this.version = params.getVersion(); + this.url = params.getUrl(); + this.method = params.getMethod(); + this.fallbackUrl = params.getFallbackUrl(); + this.fallbackMethod = params.getFallbackMethod(); + this.viStatusCallback = params.getStatusCallback(); + this.viStatusCallbackMethod = params.getStatusCallbackMethod(); + this.emailAddress = params.getEmailAddress(); + this.configuration = params.getConfiguration(); + this.callManager = params.getCallManager(); // this.asrService = asr(configuration.subset("speech-recognizer")); // this.faxService = fax(configuration.subset("fax-service")); - this.smsService = sms; + this.smsService = params.getSmsService(); this.smsSessions = new HashMap(); - this.storage = storage; + this.storage = params.getStorage(); // this.synthesizer = tts(configuration.subset("speech-synthesizer")); final Configuration runtime = configuration.subset("runtime-settings"); // String path = runtime.getString("cache-path"); @@ -198,7 +187,16 @@ public SubVoiceInterpreter(final Configuration configuration, final Sid account, // uri = uri + accountId.toString(); // this.cache = cache(path, uri); this.downloader = downloader(); - this.hangupOnEnd = hangupOnEnd; + this.hangupOnEnd = params.getHangupOnEnd(); + } + + public static Props props(final SubVoiceInterpreterParams params) { + return new Props(new UntypedActorFactory() { + @Override + public Actor create() throws Exception { + return new SubVoiceInterpreter(params); + } + }); } private Notification notification(final int log, final int error, final String message) { diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreterBuilder.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreterBuilder.java deleted file mode 100644 index 4c1a387395..0000000000 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreterBuilder.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * TeleStax, Open Source Cloud Communications - * Copyright 2011-2014, Telestax Inc and individual contributors - * by the @authors tag. - * - * This program is free software: you can redistribute it and/or modify - * under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation; either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * - */ -package org.restcomm.connect.interpreter; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorFactory; -import org.apache.commons.configuration.Configuration; -import org.apache.log4j.Logger; -import org.restcomm.connect.commons.dao.Sid; -import org.restcomm.connect.dao.DaoManager; - -import java.net.URI; - -/** - * @author quintana.thomas@gmail.com (Thomas Quintana) - */ -public final class SubVoiceInterpreterBuilder { - private Logger logger = Logger.getLogger(SubVoiceInterpreterBuilder.class); - private final ActorSystem system; - private Configuration configuration; - private DaoManager storage; - private ActorRef calls; - private ActorRef conferences; - private ActorRef sms; - private Sid account; - private Sid phone; - private String version; - private URI url; - private String method; - private URI fallbackUrl; - private String fallbackMethod; - private URI statusCallback; - private String statusCallbackMethod; - private String emailAddress; - - private Boolean hangupOnEnd = false; - - /** - * @author thomas.quintana@telestax.com (Thomas Quintana) - */ - public SubVoiceInterpreterBuilder(final ActorSystem system) { - super(); - this.system = system; - } - - public ActorRef build() { - final Props props = new Props(new UntypedActorFactory() { - private static final long serialVersionUID = 1L; - - @Override - public UntypedActor create() throws Exception { - return new SubVoiceInterpreter(configuration, account, phone, version, url, method, fallbackUrl, - fallbackMethod, statusCallback, statusCallbackMethod, emailAddress, calls, conferences, sms, storage, - hangupOnEnd); - } - }); - return system.actorOf(props); - } - - public void setConfiguration(final Configuration configuration) { - this.configuration = configuration; - } - - public void setStorage(final DaoManager storage) { - this.storage = storage; - } - - public void setCallManager(final ActorRef calls) { - this.calls = calls; - } - - public void setConferenceManager(final ActorRef conferences) { - this.conferences = conferences; - } - - public void setSmsService(final ActorRef sms) { - this.sms = sms; - } - - public void setAccount(final Sid account) { - this.account = account; - } - - public void setPhone(final Sid phone) { - this.phone = phone; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public void setMethod(final String method) { - this.method = method; - } - - public void setFallbackUrl(final URI fallbackUrl) { - this.fallbackUrl = fallbackUrl; - } - - public void setFallbackMethod(final String fallbackMethod) { - this.fallbackMethod = fallbackMethod; - } - - public void setStatusCallback(final URI statusCallback) { - this.statusCallback = statusCallback; - } - - public void setStatusCallbackMethod(final String statusCallbackMethod) { - this.statusCallbackMethod = statusCallbackMethod; - } - - public void setEmailAddress(final String emailAddress) { - this.emailAddress = emailAddress; - } - - public void setVersion(final String version) { - this.version = version; - } - - public void setHangupOnEnd(final Boolean hangupOnEnd) { - this.hangupOnEnd = hangupOnEnd; - } -} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreterParams.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreterParams.java new file mode 100644 index 0000000000..b79a5e2cb2 --- /dev/null +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/SubVoiceInterpreterParams.java @@ -0,0 +1,241 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +package org.restcomm.connect.interpreter; + +import akka.actor.ActorRef; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.dao.DaoManager; + +import java.net.URI; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public final class SubVoiceInterpreterParams { + + private Configuration configuration; + private DaoManager storage; + private ActorRef callManager; + private ActorRef conferenceCenter; + private ActorRef smsService; + private Sid account; + private Sid phone; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + private URI statusCallback; + private String statusCallbackMethod; + private String emailAddress; + + private Boolean hangupOnEnd; + + private SubVoiceInterpreterParams(Configuration configuration, DaoManager storage, ActorRef callManager, ActorRef conferenceCenter, ActorRef smsService, Sid account, Sid phone, String version, URI url, String method, URI fallbackUrl, String fallbackMethod, URI statusCallback, String statusCallbackMethod, String emailAddress, Boolean hangupOnEnd) { + this.configuration = configuration; + this.storage = storage; + this.callManager = callManager; + this.conferenceCenter = conferenceCenter; + this.smsService = smsService; + this.account = account; + this.phone = phone; + this.version = version; + this.url = url; + this.method = method; + this.fallbackUrl = fallbackUrl; + this.fallbackMethod = fallbackMethod; + this.statusCallback = statusCallback; + this.statusCallbackMethod = statusCallbackMethod; + this.emailAddress = emailAddress; + this.hangupOnEnd = hangupOnEnd; + } + + public Configuration getConfiguration() { + return configuration; + } + + public DaoManager getStorage() { + return storage; + } + + public ActorRef getCallManager() { + return callManager; + } + + public ActorRef getConferenceCenter() { + return conferenceCenter; + } + + public ActorRef getSmsService() { + return smsService; + } + + public Sid getAccount() { + return account; + } + + public Sid getPhone() { + return phone; + } + + public String getVersion() { + return version; + } + + public URI getUrl() { + return url; + } + + public String getMethod() { + return method; + } + + public URI getFallbackUrl() { + return fallbackUrl; + } + + public String getFallbackMethod() { + return fallbackMethod; + } + + public URI getStatusCallback() { + return statusCallback; + } + + public String getStatusCallbackMethod() { + return statusCallbackMethod; + } + + public String getEmailAddress() { + return emailAddress; + } + + public Boolean getHangupOnEnd() { + return hangupOnEnd; + } + + public static final class Builder { + private Configuration configuration; + private DaoManager storage; + private ActorRef callManager; + private ActorRef conferenceCenter; + private ActorRef smsService; + private Sid account; + private Sid phone; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + private URI statusCallback; + private String statusCallbackMethod; + private String emailAddress; + private Boolean hangupOnEnd = false; + + public Builder() { + } + + public Builder setConfiguration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + public Builder setStorage(DaoManager storage) { + this.storage = storage; + return this; + } + + public Builder setCallManager(ActorRef callManager) { + this.callManager = callManager; + return this; + } + + public Builder setConferenceCenter(ActorRef conferenceCenter) { + this.conferenceCenter = conferenceCenter; + return this; + } + + public Builder setSmsService(ActorRef smsService) { + this.smsService = smsService; + return this; + } + + public Builder setAccount(Sid account) { + this.account = account; + return this; + } + + public Builder setPhone(Sid phone) { + this.phone = phone; + return this; + } + + public Builder setVersion(String version) { + this.version = version; + return this; + } + + public Builder setUrl(URI url) { + this.url = url; + return this; + } + + public Builder setMethod(String method) { + this.method = method; + return this; + } + + public Builder setFallbackUrl(URI fallbackUrl) { + this.fallbackUrl = fallbackUrl; + return this; + } + + public Builder setFallbackMethod(String fallbackMethod) { + this.fallbackMethod = fallbackMethod; + return this; + } + + public Builder setStatusCallback(URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public Builder setStatusCallbackMethod(String statusCallbackMethod) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public Builder setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + return this; + } + + public Builder setHangupOnEnd(Boolean hangupOnEnd) { + this.hangupOnEnd = hangupOnEnd; + return this; + } + + public SubVoiceInterpreterParams build() { + return new SubVoiceInterpreterParams(configuration, storage, callManager, conferenceCenter, smsService, account, phone, version, url, method, fallbackUrl, fallbackMethod, statusCallback, statusCallbackMethod, emailAddress, hangupOnEnd); + } + } +} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreter.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreter.java index 75ecc2a334..7c263fbdc4 100644 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreter.java +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreter.java @@ -19,14 +19,16 @@ */ package org.restcomm.connect.interpreter; +import akka.actor.Actor; import akka.actor.ActorRef; +import akka.actor.Props; import akka.actor.ReceiveTimeout; import akka.actor.UntypedActorContext; +import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; import akka.pattern.AskTimeoutException; import akka.util.Timeout; - import org.apache.commons.configuration.Configuration; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; @@ -50,7 +52,6 @@ import org.restcomm.connect.commons.telephony.CreateCallType; import org.restcomm.connect.commons.util.UriUtils; import org.restcomm.connect.dao.CallDetailRecordsDao; -import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.dao.NotificationsDao; import org.restcomm.connect.dao.entities.CallDetailRecord; import org.restcomm.connect.dao.entities.Notification; @@ -108,7 +109,6 @@ import org.restcomm.connect.telephony.api.StopBridge; import org.restcomm.connect.telephony.api.StopConference; import org.restcomm.connect.tts.api.SpeechSynthesizerResponse; - import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -117,7 +117,6 @@ import javax.servlet.sip.SipServletRequest; import javax.servlet.sip.SipServletResponse; import javax.servlet.sip.SipSession; - import java.io.IOException; import java.math.BigDecimal; import java.net.MalformedURLException; @@ -222,12 +221,7 @@ public final class VoiceInterpreter extends BaseVoiceInterpreter { private String conferenceNameWithAccountAndFriendlyName; private Sid callSid; - public VoiceInterpreter(final Configuration configuration, final Sid account, final Sid phone, final String version, - final URI url, final String method, final URI fallbackUrl, final String fallbackMethod, final URI viStatusCallback, - final String statusCallbackMethod, final String referTarget, final String transferor, final String transferee, - final String emailAddress, final ActorRef callManager, - final ActorRef conferenceManager, final ActorRef bridgeManager, final ActorRef sms, final DaoManager storage, final ActorRef monitoring, final String rcml, - final boolean asImsUa, final String imsUaLogin, final String imsUaPassword) { + private VoiceInterpreter(VoiceInterpreterParams params) { super(); final ActorRef source = self(); downloadingRcml = new State("downloading rcml", new DownloadingRcml(source), null); @@ -411,35 +405,44 @@ public VoiceInterpreter(final Configuration configuration, final Sid account, fi // Initialize the FSM. this.fsm = new FiniteStateMachine(uninitialized, transitions); // Initialize the runtime stuff. - this.accountId = account; - this.phoneId = phone; - this.version = version; - this.url = url; - this.method = method; - this.fallbackUrl = fallbackUrl; - this.fallbackMethod = fallbackMethod; - this.viStatusCallback = viStatusCallback; - this.viStatusCallbackMethod = statusCallbackMethod; - this.referTarget = referTarget; - this.transferor = transferor; - this.transferee = transferee; - this.emailAddress = emailAddress; - this.configuration = configuration; - this.callManager = callManager; - this.conferenceCenter = conferenceManager; - this.bridgeManager = bridgeManager; - this.smsService = sms; + this.accountId = params.getAccount(); + this.phoneId = params.getPhone(); + this.version = params.getVersion(); + this.url = params.getUrl(); + this.method = params.getMethod(); + this.fallbackUrl = params.getFallbackUrl(); + this.fallbackMethod = params.getFallbackMethod(); + this.viStatusCallback = params.getStatusCallback(); + this.viStatusCallbackMethod = params.getStatusCallbackMethod(); + this.referTarget = params.getReferTarget(); + this.transferor = params.getTransferor(); + this.transferee = params.getTransferee(); + this.emailAddress = params.getEmailAddress(); + this.configuration = params.getConfiguration(); + this.callManager = params.getCallManager(); + this.conferenceCenter = params.getConferenceCenter(); + this.bridgeManager = params.getBridgeManager(); + this.smsService = params.getSmsService(); this.smsSessions = new HashMap(); - this.storage = storage; + this.storage = params.getStorage(); final Configuration runtime = configuration.subset("runtime-settings"); playMusicForConference = Boolean.parseBoolean(runtime.getString("play-music-for-conference","false")); this.enable200OkDelay = this.configuration.subset("runtime-settings").getBoolean("enable-200-ok-delay",false); this.downloader = downloader(); - this.monitoring = monitoring; - this.rcml = rcml; - this.asImsUa = asImsUa; - this.imsUaLogin = imsUaLogin; - this.imsUaPassword = imsUaPassword; + this.monitoring = params.getMonitoring(); + this.rcml = params.getRcml(); + this.asImsUa = params.isAsImsUa(); + this.imsUaLogin = params.getImsUaLogin(); + this.imsUaPassword = params.getImsUaPassword(); + } + + public static Props props(final VoiceInterpreterParams params) { + return new Props(new UntypedActorFactory() { + @Override + public Actor create() throws Exception { + return new VoiceInterpreter(params); + } + }); } private boolean is(State state) { @@ -3147,7 +3150,7 @@ public void postStop() { call = null; } - system.stop(self()); + getContext().stop(self()); postCleanup(); } if(asImsUa){ @@ -3214,7 +3217,7 @@ private ActorRef buildSubVoiceInterpreter(Tag child) throws MalformedURLExceptio method = "POST"; } - final SubVoiceInterpreterBuilder builder = new SubVoiceInterpreterBuilder(system); + final SubVoiceInterpreterParams.Builder builder = new SubVoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(super.source); @@ -3223,7 +3226,9 @@ private ActorRef buildSubVoiceInterpreter(Tag child) throws MalformedURLExceptio builder.setVersion(version); builder.setUrl(url); builder.setMethod(method); - return builder.build(); + + final Props props = SubVoiceInterpreter.props(builder.build()); + return getContext().actorOf(props); } @Override diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreterBuilder.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreterBuilder.java deleted file mode 100644 index 8dccef29d5..0000000000 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreterBuilder.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * TeleStax, Open Source Cloud Communications - * Copyright 2011-2014, Telestax Inc and individual contributors - * by the @authors tag. - * - * This program is free software: you can redistribute it and/or modify - * under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation; either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * - */ -package org.restcomm.connect.interpreter; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorFactory; -import org.apache.commons.configuration.Configuration; -import org.apache.log4j.Logger; -import org.restcomm.connect.commons.dao.Sid; -import org.restcomm.connect.dao.DaoManager; - -import java.net.URI; - -/** - * @author quintana.thomas@gmail.com (Thomas Quintana) - * @author gvagenas@gmail.com (George Vagenas) - */ -public final class VoiceInterpreterBuilder { - private static Logger logger = Logger.getLogger(VoiceInterpreterBuilder.class); - private ActorSystem system; - private Configuration configuration; - private DaoManager storage; - private ActorRef calls; - private ActorRef conferences; - private ActorRef bridges; - private ActorRef sms; - private Sid account; - private Sid phone; - private String version; - private URI url; - private String method; - private URI fallbackUrl; - private String fallbackMethod; - private URI statusCallback; - private String statusCallbackMethod; - private String referTarget; - private String emailAddress; - private ActorRef monitoring; - private String rcml; - - // IMS authentication - private boolean asImsUa; - private String imsUaLogin; - private String imsUaPassword; - private String transferor; - private String transferee; - - /** - * @author thomas.quintana@telestax.com (Thomas Quintana) - */ - public VoiceInterpreterBuilder(final ActorSystem system) { - super(); - this.system = system; - } - - public ActorRef build() { - final Props props = new Props(new UntypedActorFactory() { - private static final long serialVersionUID = 1L; - - @Override - public UntypedActor create() throws Exception { - return new VoiceInterpreter(configuration, account, phone, version, url, method, fallbackUrl, fallbackMethod, - statusCallback, statusCallbackMethod, referTarget, transferor, transferee, emailAddress, calls, conferences, bridges, sms, storage, monitoring, rcml, - asImsUa, imsUaLogin, imsUaPassword); - } - }); - return system.actorOf(props); - } - - public void setConfiguration(final Configuration configuration) { - this.configuration = configuration; - } - - public void setStorage(final DaoManager storage) { - this.storage = storage; - } - - public void setCallManager(final ActorRef calls) { - this.calls = calls; - } - - public void setConferenceManager(final ActorRef conferences) { - this.conferences = conferences; - } - - public void setBridgeManager(final ActorRef bridges) { - this.bridges = bridges; - } - - public void setSmsService(final ActorRef sms) { - this.sms = sms; - } - - public void setAccount(final Sid account) { - this.account = account; - } - - public void setPhone(final Sid phone) { - this.phone = phone; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public void setMethod(final String method) { - this.method = method; - } - - public void setFallbackUrl(final URI fallbackUrl) { - this.fallbackUrl = fallbackUrl; - } - - public void setFallbackMethod(final String fallbackMethod) { - this.fallbackMethod = fallbackMethod; - } - - public void setStatusCallback(final URI statusCallback) { - this.statusCallback = statusCallback; - } - - public void setStatusCallbackMethod(final String statusCallbackMethod) { - this.statusCallbackMethod = statusCallbackMethod; - } - - public void setReferTarget(final String referTarget) { - this.referTarget = referTarget; - } - - public void setEmailAddress(final String emailAddress) { - this.emailAddress = emailAddress; - } - - public void setVersion(final String version) { - this.version = version; - } - - public void setMonitoring(ActorRef monitoring) { - this.monitoring = monitoring; - } - - public void setRcml(final String rcml) { this.rcml = rcml; } - - public void setAsImsUa(boolean asImsUa) { - this.asImsUa = asImsUa; - } - - public void setImsUaLogin(String imsUaLogin) { - this.imsUaLogin = imsUaLogin; - } - - public void setImsUaPassword(String imsUaPassword) { - this.imsUaPassword = imsUaPassword; - } - - public void setTransferor (String transferor) { - this.transferor = transferor; - } - - public void setTransferee (String transferee) { - this.transferee = transferee; - } -} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreterParams.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreterParams.java new file mode 100644 index 0000000000..edf9999ae1 --- /dev/null +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/VoiceInterpreterParams.java @@ -0,0 +1,338 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +package org.restcomm.connect.interpreter; + +import akka.actor.ActorRef; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.dao.DaoManager; + +import java.net.URI; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public final class VoiceInterpreterParams { + + private Configuration configuration; + private DaoManager storage; + private ActorRef callManager; + private ActorRef conferenceCenter; + private ActorRef bridgeManager; + private ActorRef smsService; + private Sid account; + private Sid phone; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + private URI statusCallback; + private String statusCallbackMethod; + private String referTarget; + private String emailAddress; + private ActorRef monitoring; + private String rcml; + + // IMS authentication + private boolean asImsUa; + private String imsUaLogin; + private String imsUaPassword; + private String transferor; + private String transferee; + + private VoiceInterpreterParams(Configuration configuration, DaoManager storage, ActorRef callManager, ActorRef conferences, ActorRef bridgeManager, ActorRef smsService, Sid account, Sid phone, String version, URI url, String method, URI fallbackUrl, String fallbackMethod, URI statusCallback, String statusCallbackMethod, String referTarget, String emailAddress, ActorRef monitoring, String rcml, boolean asImsUa, String imsUaLogin, String imsUaPassword, String transferor, String transferee) { + this.configuration = configuration; + this.storage = storage; + this.callManager = callManager; + this.conferenceCenter = conferences; + this.bridgeManager = bridgeManager; + this.smsService = smsService; + this.account = account; + this.phone = phone; + this.version = version; + this.url = url; + this.method = method; + this.fallbackUrl = fallbackUrl; + this.fallbackMethod = fallbackMethod; + this.statusCallback = statusCallback; + this.statusCallbackMethod = statusCallbackMethod; + this.referTarget = referTarget; + this.emailAddress = emailAddress; + this.monitoring = monitoring; + this.rcml = rcml; + this.asImsUa = asImsUa; + this.imsUaLogin = imsUaLogin; + this.imsUaPassword = imsUaPassword; + this.transferor = transferor; + this.transferee = transferee; + } + + public Configuration getConfiguration() { + return configuration; + } + + public DaoManager getStorage() { + return storage; + } + + public ActorRef getCallManager() { + return callManager; + } + + public ActorRef getConferenceCenter() { + return conferenceCenter; + } + + public ActorRef getBridgeManager() { + return bridgeManager; + } + + public ActorRef getSmsService() { + return smsService; + } + + public Sid getAccount() { + return account; + } + + public Sid getPhone() { + return phone; + } + + public String getVersion() { + return version; + } + + public URI getUrl() { + return url; + } + + public String getMethod() { + return method; + } + + public URI getFallbackUrl() { + return fallbackUrl; + } + + public String getFallbackMethod() { + return fallbackMethod; + } + + public URI getStatusCallback() { + return statusCallback; + } + + public String getStatusCallbackMethod() { + return statusCallbackMethod; + } + + public String getReferTarget() { + return referTarget; + } + + public String getEmailAddress() { + return emailAddress; + } + + public ActorRef getMonitoring() { + return monitoring; + } + + public String getRcml() { + return rcml; + } + + public boolean isAsImsUa() { + return asImsUa; + } + + public String getImsUaLogin() { + return imsUaLogin; + } + + public String getImsUaPassword() { + return imsUaPassword; + } + + public String getTransferor() { + return transferor; + } + + public String getTransferee() { + return transferee; + } + + public static final class Builder { + private Configuration configuration; + private DaoManager storage; + private ActorRef callManager; + private ActorRef conferenceCenter; + private ActorRef bridgeManager; + private ActorRef smsService; + private Sid account; + private Sid phone; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + private URI statusCallback; + private String statusCallbackMethod; + private String referTarget; + private String emailAddress; + private ActorRef monitoring; + private String rcml; + private boolean asImsUa; + private String imsUaLogin; + private String imsUaPassword; + private String transferor; + private String transferee; + + public Builder() { + } + + public Builder setConfiguration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + public Builder setStorage(DaoManager storage) { + this.storage = storage; + return this; + } + + public Builder setCallManager(ActorRef callManager) { + this.callManager = callManager; + return this; + } + + public Builder setConferenceCenter(ActorRef conferenceCenter) { + this.conferenceCenter = conferenceCenter; + return this; + } + + public Builder setBridgeManager(ActorRef bridgeManager) { + this.bridgeManager = bridgeManager; + return this; + } + + public Builder setSmsService(ActorRef smsService) { + this.smsService = smsService; + return this; + } + + public Builder setAccount(Sid account) { + this.account = account; + return this; + } + + public Builder setPhone(Sid phone) { + this.phone = phone; + return this; + } + + public Builder setVersion(String version) { + this.version = version; + return this; + } + + public Builder setUrl(URI url) { + this.url = url; + return this; + } + + public Builder setMethod(String method) { + this.method = method; + return this; + } + + public Builder setFallbackUrl(URI fallbackUrl) { + this.fallbackUrl = fallbackUrl; + return this; + } + + public Builder setFallbackMethod(String fallbackMethod) { + this.fallbackMethod = fallbackMethod; + return this; + } + + public Builder setStatusCallback(URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public Builder setStatusCallbackMethod(String statusCallbackMethod) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public Builder setReferTarget(String referTarget) { + this.referTarget = referTarget; + return this; + } + + public Builder setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + return this; + } + + public Builder setMonitoring(ActorRef monitoring) { + this.monitoring = monitoring; + return this; + } + + public Builder setRcml(String rcml) { + this.rcml = rcml; + return this; + } + + public Builder setAsImsUa(boolean asImsUa) { + this.asImsUa = asImsUa; + return this; + } + + public Builder setImsUaLogin(String imsUaLogin) { + this.imsUaLogin = imsUaLogin; + return this; + } + + public Builder setImsUaPassword(String imsUaPassword) { + this.imsUaPassword = imsUaPassword; + return this; + } + + public Builder setTransferor(String transferor) { + this.transferor = transferor; + return this; + } + + public Builder setTransferee(String transferee) { + this.transferee = transferee; + return this; + } + + public VoiceInterpreterParams build() { + return new VoiceInterpreterParams(configuration, storage, callManager, conferenceCenter, bridgeManager, smsService, account, phone, version, url, method, fallbackUrl, fallbackMethod, statusCallback, statusCallbackMethod, referTarget, emailAddress, monitoring, rcml, asImsUa, imsUaLogin, imsUaPassword, transferor, transferee); + } + } +} diff --git a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/rcml/Parser.java b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/rcml/Parser.java index 6e2a86a0ac..a49b3a3270 100644 --- a/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/rcml/Parser.java +++ b/restcomm/restcomm.interpreter/src/main/java/org/restcomm/connect/interpreter/rcml/Parser.java @@ -20,9 +20,12 @@ package org.restcomm.connect.interpreter.rcml; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import org.apache.log4j.Logger; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -32,15 +35,12 @@ import java.util.List; import java.util.Stack; -import javax.xml.stream.XMLInputFactory; import static javax.xml.stream.XMLStreamConstants.*; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class Parser extends UntypedActor { +public final class Parser extends RestcommUntypedActor { private static Logger logger = Logger.getLogger(Parser.class); private Tag document; private Iterator iterator; diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Connection.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Connection.java index cee9591993..4cfed505a3 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Connection.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Connection.java @@ -19,23 +19,8 @@ */ package org.restcomm.connect.mgcp; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.restcomm.connect.commons.fsm.Action; -import org.restcomm.connect.commons.fsm.FiniteStateMachine; -import org.restcomm.connect.commons.fsm.State; -import org.restcomm.connect.commons.fsm.Transition; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.Observing; -import org.restcomm.connect.commons.patterns.StopObserving; - import akka.actor.ActorRef; import akka.actor.ReceiveTimeout; -import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; import akka.event.Logging; import akka.event.LoggingAdapter; @@ -54,12 +39,26 @@ import jain.protocol.ip.mgcp.message.parms.LocalOptionValue; import jain.protocol.ip.mgcp.message.parms.NotifiedEntity; import jain.protocol.ip.mgcp.message.parms.ReturnCode; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.commons.fsm.Action; +import org.restcomm.connect.commons.fsm.FiniteStateMachine; +import org.restcomm.connect.commons.fsm.State; +import org.restcomm.connect.commons.fsm.Transition; +import org.restcomm.connect.commons.patterns.Observe; +import org.restcomm.connect.commons.patterns.Observing; +import org.restcomm.connect.commons.patterns.StopObserving; import scala.concurrent.duration.Duration; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; + /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class Connection extends UntypedActor { +public final class Connection extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); // Finite state machine stuff. private final State uninitialized; diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/GenericEndpoint.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/GenericEndpoint.java index 066c68564b..5efbc24668 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/GenericEndpoint.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/GenericEndpoint.java @@ -19,33 +19,31 @@ */ package org.restcomm.connect.mgcp; +import akka.actor.ActorRef; +import akka.actor.ReceiveTimeout; +import akka.event.Logging; +import akka.event.LoggingAdapter; import jain.protocol.ip.mgcp.JainMgcpResponseEvent; import jain.protocol.ip.mgcp.message.DeleteConnection; import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier; import jain.protocol.ip.mgcp.message.parms.NotifiedEntity; import jain.protocol.ip.mgcp.message.parms.ReturnCode; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.commons.patterns.Observe; +import org.restcomm.connect.commons.patterns.Observing; +import org.restcomm.connect.commons.patterns.StopObserving; +import scala.concurrent.duration.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.Observing; -import org.restcomm.connect.commons.patterns.StopObserving; - -import scala.concurrent.duration.Duration; -import akka.actor.ActorRef; -import akka.actor.ReceiveTimeout; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; - /** * @author quintana.thomas@gmail.com (Thomas Quintana) * @author maria.farooq@telestax.com (Maria Farooq) */ -public abstract class GenericEndpoint extends UntypedActor { +public abstract class GenericEndpoint extends RestcommUntypedActor { protected final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/IvrEndpoint.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/IvrEndpoint.java index 758a9bd214..8077eb2a07 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/IvrEndpoint.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/IvrEndpoint.java @@ -19,16 +19,6 @@ */ package org.restcomm.connect.mgcp; -import static jain.protocol.ip.mgcp.message.parms.ReturnCode.Transaction_Executed_Normally; - -import java.util.HashMap; -import java.util.Map; - -import org.mobicents.protocols.mgcp.jain.pkg.AUMgcpEvent; -import org.mobicents.protocols.mgcp.jain.pkg.AUPackage; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.StopObserving; - import akka.actor.ActorRef; import jain.protocol.ip.mgcp.JainIPMgcpException; import jain.protocol.ip.mgcp.JainMgcpResponseEvent; @@ -45,6 +35,15 @@ import jain.protocol.ip.mgcp.message.parms.ReturnCode; import jain.protocol.ip.mgcp.pkg.MgcpEvent; import jain.protocol.ip.mgcp.pkg.PackageName; +import org.mobicents.protocols.mgcp.jain.pkg.AUMgcpEvent; +import org.mobicents.protocols.mgcp.jain.pkg.AUPackage; +import org.restcomm.connect.commons.patterns.Observe; +import org.restcomm.connect.commons.patterns.StopObserving; + +import java.util.HashMap; +import java.util.Map; + +import static jain.protocol.ip.mgcp.message.parms.ReturnCode.Transaction_Executed_Normally; /** * @author quintana.thomas@gmail.com (Thomas Quintana) diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Link.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Link.java index bd6e01d1da..052fac01f2 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Link.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/Link.java @@ -19,23 +19,8 @@ */ package org.restcomm.connect.mgcp; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.restcomm.connect.commons.fsm.Action; -import org.restcomm.connect.commons.fsm.FiniteStateMachine; -import org.restcomm.connect.commons.fsm.State; -import org.restcomm.connect.commons.fsm.Transition; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.Observing; -import org.restcomm.connect.commons.patterns.StopObserving; - import akka.actor.ActorRef; import akka.actor.ReceiveTimeout; -import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; import akka.event.Logging; import akka.event.LoggingAdapter; @@ -50,12 +35,26 @@ import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier; import jain.protocol.ip.mgcp.message.parms.NotifiedEntity; import jain.protocol.ip.mgcp.message.parms.ReturnCode; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.commons.fsm.Action; +import org.restcomm.connect.commons.fsm.FiniteStateMachine; +import org.restcomm.connect.commons.fsm.State; +import org.restcomm.connect.commons.fsm.Transition; +import org.restcomm.connect.commons.patterns.Observe; +import org.restcomm.connect.commons.patterns.Observing; +import org.restcomm.connect.commons.patterns.StopObserving; import scala.concurrent.duration.Duration; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; + /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class Link extends UntypedActor { +public final class Link extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); // Finite state machine stuff. private final State uninitialized; diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MediaGateway.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MediaGateway.java index 242222b3f1..a892397fb9 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MediaGateway.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MediaGateway.java @@ -21,7 +21,6 @@ import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; @@ -40,6 +39,7 @@ import jain.protocol.ip.mgcp.message.Notify; import jain.protocol.ip.mgcp.message.parms.ConnectionIdentifier; import jain.protocol.ip.mgcp.message.parms.NotifiedEntity; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.RevolvingCounter; import java.net.InetAddress; @@ -50,7 +50,7 @@ /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class MediaGateway extends UntypedActor implements JainMgcpListener { +public final class MediaGateway extends RestcommUntypedActor implements JainMgcpListener { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); // MediaGateway connection information. private String name; @@ -77,13 +77,11 @@ public final class MediaGateway extends UntypedActor implements JainMgcpListener private RevolvingCounter requestIdPool; private RevolvingCounter sessionIdPool; private RevolvingCounter transactionIdPool; - private ActorSystem system; public MediaGateway() { super(); notificationListeners = new ConcurrentHashMap(); responseListeners = new ConcurrentHashMap(); - system = context().system(); } private ActorRef getConnection(final Object message) { @@ -99,7 +97,7 @@ public UntypedActor create() throws Exception { return new Connection(gateway, session, agent, timeout); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private ActorRef getBridgeEndpoint(final Object message) { @@ -127,7 +125,7 @@ public Actor create() throws Exception { } }); } - return system.actorOf(props); + return getContext().actorOf(props); } private ActorRef getConferenceEndpoint(final Object message) { @@ -143,7 +141,7 @@ public UntypedActor create() throws Exception { return new ConferenceEndpoint(gateway, session, agent, domain, timeout, endpointName); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private MediaGatewayInfo getInfo(final Object message) { @@ -163,7 +161,7 @@ public UntypedActor create() throws Exception { return new IvrEndpoint(gateway, session, agent, domain, timeout, endpointName); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private ActorRef getLink(final Object message) { @@ -179,7 +177,7 @@ public UntypedActor create() throws Exception { return new Link(gateway, session, agent, timeout, connectionIdentifier); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private ActorRef getPacketRelayEndpoint(final Object message) { @@ -194,7 +192,7 @@ public UntypedActor create() throws Exception { return new PacketRelayEndpoint(gateway, session, agent, domain, timeout); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private MediaSession getSession() { diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockConnection.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockConnection.java index 76c6fd3ffc..4430bfc9cb 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockConnection.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockConnection.java @@ -21,7 +21,6 @@ import akka.actor.ActorRef; import akka.actor.ReceiveTimeout; -import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; import akka.event.Logging; import akka.event.LoggingAdapter; @@ -40,6 +39,7 @@ import jain.protocol.ip.mgcp.message.parms.LocalOptionValue; import jain.protocol.ip.mgcp.message.parms.NotifiedEntity; import jain.protocol.ip.mgcp.message.parms.ReturnCode; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -58,7 +58,7 @@ /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class MockConnection extends UntypedActor { +public final class MockConnection extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); // Finite state machine stuff. private final State uninitialized; diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java index 1c3ab818c1..f6b3985261 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java @@ -47,6 +47,7 @@ import jain.protocol.ip.mgcp.pkg.MgcpEvent; import org.mobicents.protocols.mgcp.jain.pkg.AUMgcpEvent; import org.mobicents.protocols.mgcp.jain.pkg.AUPackage; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.RevolvingCounter; import javax.sdp.SdpFactory; @@ -59,7 +60,7 @@ /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public class MockMediaGateway extends UntypedActor { +public class MockMediaGateway extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); // Session description for the mock media gateway. private static final String sdp = "v=0\n" + "o=- 1362546170756 1 IN IP4 192.168.1.100\n" + "s=Mobicents Media Server\n" diff --git a/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/AbstractMockMediaGateway.java b/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/AbstractMockMediaGateway.java index 83e1c70815..10179c443f 100644 --- a/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/AbstractMockMediaGateway.java +++ b/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/AbstractMockMediaGateway.java @@ -24,19 +24,18 @@ import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; - import jain.protocol.ip.mgcp.JainMgcpCommandEvent; import jain.protocol.ip.mgcp.JainMgcpResponseEvent; import jain.protocol.ip.mgcp.message.NotificationRequest; import jain.protocol.ip.mgcp.message.parms.NotifiedEntity; - +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.RevolvingCounter; /** * @author thomas.quintana@telestax.com (Thomas Quintana) * @author maria.farooq@telestax.com (Maria Farooq) */ -public abstract class AbstractMockMediaGateway extends UntypedActor { +public abstract class AbstractMockMediaGateway extends RestcommUntypedActor { // Call agent. protected NotifiedEntity agent; // Media gateway domain name. diff --git a/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/EndpointTest.java b/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/EndpointTest.java index e09afe0580..2707b87391 100644 --- a/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/EndpointTest.java +++ b/restcomm/restcomm.mgcp/src/test/java/org/restcomm/connect/mgcp/EndpointTest.java @@ -19,17 +19,6 @@ */ package org.restcomm.connect.mgcp; -import static org.junit.Assert.assertTrue; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.mobicents.protocols.mgcp.jain.pkg.AUMgcpEvent; -import org.mobicents.protocols.mgcp.jain.pkg.AUPackage; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.Observing; -import org.restcomm.connect.commons.patterns.StopObserving; - import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Props; @@ -44,6 +33,16 @@ import jain.protocol.ip.mgcp.message.parms.EventName; import jain.protocol.ip.mgcp.message.parms.ReturnCode; import jain.protocol.ip.mgcp.pkg.MgcpEvent; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mobicents.protocols.mgcp.jain.pkg.AUMgcpEvent; +import org.mobicents.protocols.mgcp.jain.pkg.AUPackage; +import org.restcomm.connect.commons.patterns.Observe; +import org.restcomm.connect.commons.patterns.Observing; +import org.restcomm.connect.commons.patterns.StopObserving; + +import static org.junit.Assert.assertTrue; /** * @author maria.farooq@telestax.com (Maria Farooq) diff --git a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java index 9f7a672829..1e6435d98c 100644 --- a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java +++ b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java @@ -21,10 +21,10 @@ package org.restcomm.connect.monitoringservice; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import org.restcomm.connect.commons.configuration.RestcommConfiguration; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.patterns.Observing; import org.restcomm.connect.commons.patterns.StopObserving; import org.restcomm.connect.dao.DaoManager; @@ -55,7 +55,7 @@ /** * @author gvagenas */ -public class MonitoringService extends UntypedActor{ +public class MonitoringService extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private DaoManager daoManager; diff --git a/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/ConferenceMediaResourceControllerGeneric.java b/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/ConferenceMediaResourceControllerGeneric.java index 7765ce469f..90544b0424 100644 --- a/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/ConferenceMediaResourceControllerGeneric.java +++ b/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/ConferenceMediaResourceControllerGeneric.java @@ -21,7 +21,6 @@ package org.restcomm.connect.mrb; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; @@ -30,6 +29,7 @@ import org.apache.commons.configuration.Configuration; import org.joda.time.DateTime; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -66,7 +66,7 @@ /** * @author maria.farooq@telestax.com (Maria Farooq) */ -public class ConferenceMediaResourceControllerGeneric extends UntypedActor{ +public class ConferenceMediaResourceControllerGeneric extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); @@ -101,12 +101,10 @@ public class ConferenceMediaResourceControllerGeneric extends UntypedActor{ // Observer pattern protected final List observers; protected ActorRef mrb; - protected ActorSystem system; public ConferenceMediaResourceControllerGeneric(ActorRef localMediaGateway, final Configuration configuration, final DaoManager storage, final ActorRef mrb){ super(); final ActorRef source = self(); - this.system = context().system(); // Initialize the states for the FSM. this.uninitialized = new State("uninitialized", null, null); this.creatingMediaGroup = new State("creating media group", new CreatingMediaGroup(source), null); @@ -382,7 +380,7 @@ public UntypedActor create() throws Exception { return new MgcpMediaGroup(localMediaGateway, localMediaSession, localConfernceEndpoint); } }); - return system.actorOf(props); + return getContext().actorOf(props); } @Override diff --git a/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java b/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java index 15b5144255..b89065c683 100644 --- a/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java +++ b/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java @@ -20,17 +20,20 @@ */ package org.restcomm.connect.mrb; -import java.net.InetAddress; -import java.net.URI; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import akka.actor.ActorRef; +import akka.actor.Props; +import akka.actor.UntypedActor; +import akka.actor.UntypedActorFactory; +import akka.event.Logging; +import akka.event.LoggingAdapter; +import jain.protocol.ip.mgcp.CreateProviderException; +import jain.protocol.ip.mgcp.JainMgcpProvider; +import jain.protocol.ip.mgcp.JainMgcpStack; import org.apache.commons.configuration.Configuration; import org.joda.time.DateTime; import org.mobicents.protocols.mgcp.stack.JainMgcpStackImpl; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.loader.ObjectFactory; import org.restcomm.connect.dao.CallDetailRecordsDao; import org.restcomm.connect.dao.ConferenceDetailRecordsDao; @@ -48,20 +51,17 @@ import org.restcomm.connect.mrb.api.StartMediaResourceBroker; import org.restcomm.connect.telephony.api.ConferenceStateChanged; -import akka.actor.ActorRef; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorFactory; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import jain.protocol.ip.mgcp.CreateProviderException; -import jain.protocol.ip.mgcp.JainMgcpProvider; -import jain.protocol.ip.mgcp.JainMgcpStack; +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author maria.farooq@telestax.com (Maria Farooq) */ -public class MediaResourceBrokerGeneric extends UntypedActor{ +public class MediaResourceBrokerGeneric extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); @@ -144,7 +144,7 @@ public UntypedActor create() throws Exception { return (UntypedActor) new ObjectFactory(loader).getObjectInstance(classpath); } }); - return context().system().actorOf(props); + return getContext().actorOf(props); } /** @@ -201,7 +201,7 @@ public UntypedActor create() throws Exception { return new ConferenceMediaResourceControllerGeneric(localMediaGateway, configuration, storage, self()); } }); - return context().system().actorOf(props); + return getContext().actorOf(props); } /** diff --git a/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaGroup.java b/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaGroup.java index 9c43235262..484faadc5f 100644 --- a/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaGroup.java +++ b/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaGroup.java @@ -19,11 +19,11 @@ */ package org.restcomm.connect.mscontrol.api; -import akka.actor.UntypedActor; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public abstract class MediaGroup extends UntypedActor { +public abstract class MediaGroup extends RestcommUntypedActor { } diff --git a/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerController.java b/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerController.java index 03fbc029fb..527aacb6e0 100644 --- a/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerController.java +++ b/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerController.java @@ -19,17 +19,16 @@ */ package org.restcomm.connect.mscontrol.api; -import org.restcomm.connect.commons.fsm.Action; - import akka.actor.ActorRef; -import akka.actor.UntypedActor; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.commons.fsm.Action; /** * Controls the flow of media sessions. * * @author Henrique Rosa (henrique.rosa@telestax.com) */ -public abstract class MediaServerController extends UntypedActor { +public abstract class MediaServerController extends RestcommUntypedActor { protected MediaServerController() { super(); diff --git a/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerControllerFactory.java b/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerControllerFactory.java index 846ea1101d..aaa74d9c8d 100644 --- a/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerControllerFactory.java +++ b/restcomm/restcomm.mscontrol.api/src/main/java/org/restcomm/connect/mscontrol/api/MediaServerControllerFactory.java @@ -21,7 +21,7 @@ package org.restcomm.connect.mscontrol.api; -import akka.actor.ActorRef; +import akka.actor.Props; /** * @author Henrique Rosa (henrique.rosa@telestax.com) @@ -30,24 +30,24 @@ public interface MediaServerControllerFactory { /** - * Provides a new Media Server Controller for a Call. + * Provides a new Media Server Controller Props for a Call. * - * @return The media server controller + * @return The media server controller props */ - ActorRef provideCallController(); + Props provideCallControllerProps(); /** - * Provides a new Media Server Controller for a Conference. + * Provides a new Media Server Controller Props for a Conference. * - * @return The media server controller + * @return The media server controller props */ - ActorRef provideConferenceController(); + Props provideConferenceControllerProps(); /** - * Provides a new Media Server Controller for a Bridge. + * Provides a new Media Server Controller Props for a Bridge. * - * @return The media server controller + * @return The media server controller props */ - ActorRef provideBridgeController(); + Props provideBridgeControllerProps(); } diff --git a/restcomm/restcomm.mscontrol.jsr309/src/main/java/org/restcomm/connect/mscontrol/jsr309/Jsr309ControllerFactory.java b/restcomm/restcomm.mscontrol.jsr309/src/main/java/org/restcomm/connect/mscontrol/jsr309/Jsr309ControllerFactory.java index 3b4ba29bd6..2bc37af188 100644 --- a/restcomm/restcomm.mscontrol.jsr309/src/main/java/org/restcomm/connect/mscontrol/jsr309/Jsr309ControllerFactory.java +++ b/restcomm/restcomm.mscontrol.jsr309/src/main/java/org/restcomm/connect/mscontrol/jsr309/Jsr309ControllerFactory.java @@ -22,8 +22,6 @@ package org.restcomm.connect.mscontrol.jsr309; import akka.actor.Actor; -import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActorFactory; import org.apache.log4j.Logger; @@ -39,8 +37,6 @@ public class Jsr309ControllerFactory implements MediaServerControllerFactory { private static Logger logger = Logger.getLogger(Jsr309ControllerFactory.class); - // Actor supervisor - private final ActorSystem system; // JSR-309 private final MsControlFactory msControlFactory; @@ -53,10 +49,7 @@ public class Jsr309ControllerFactory implements MediaServerControllerFactory { // Media Server Info private final MediaServerInfo mediaServerInfo; - public Jsr309ControllerFactory(ActorSystem system, MediaServerInfo mediaServerInfo, MsControlFactory msControlFactory) { - // Actor supervisor - this.system = system; - + public Jsr309ControllerFactory(MediaServerInfo mediaServerInfo, MsControlFactory msControlFactory) { // Factories this.msControlFactory = msControlFactory; this.callControllerFactory = new CallControllerFactory(); @@ -68,21 +61,18 @@ public Jsr309ControllerFactory(ActorSystem system, MediaServerInfo mediaServerIn } @Override - public ActorRef provideCallController() { - final Props props = new Props(this.callControllerFactory); - return system.actorOf(props); + public Props provideCallControllerProps() { + return new Props(this.callControllerFactory); } @Override - public ActorRef provideConferenceController() { - final Props props = new Props(this.conferenceControllerFactory); - return system.actorOf(props); + public Props provideConferenceControllerProps() { + return new Props(this.conferenceControllerFactory); } @Override - public ActorRef provideBridgeController() { - final Props props = new Props(this.bridgeControllerFactory); - return system.actorOf(props); + public Props provideBridgeControllerProps() { + return new Props(this.bridgeControllerFactory); } private final class CallControllerFactory implements UntypedActorFactory { diff --git a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MgcpMediaGroup.java b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MgcpMediaGroup.java index 09baea9ea7..4832b37605 100644 --- a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MgcpMediaGroup.java +++ b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MgcpMediaGroup.java @@ -20,12 +20,11 @@ package org.restcomm.connect.mscontrol.mms; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - +import akka.actor.ActorRef; +import akka.event.Logging; +import akka.event.LoggingAdapter; +import jain.protocol.ip.mgcp.message.parms.ConnectionIdentifier; +import jain.protocol.ip.mgcp.message.parms.ConnectionMode; import jain.protocol.ip.mgcp.pkg.MgcpEvent; import org.mobicents.protocols.mgcp.jain.pkg.AUMgcpEvent; import org.restcomm.connect.commons.fsm.Action; @@ -63,11 +62,11 @@ import org.restcomm.connect.mscontrol.api.messages.Stop; import org.restcomm.connect.mscontrol.api.messages.StopMediaGroup; -import akka.actor.ActorRef; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import jain.protocol.ip.mgcp.message.parms.ConnectionIdentifier; -import jain.protocol.ip.mgcp.message.parms.ConnectionMode; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * @author quintana.thomas@gmail.com (Thomas Quintana) diff --git a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsBridgeController.java b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsBridgeController.java index c1bdba0fa2..e5aef04d07 100644 --- a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsBridgeController.java +++ b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsBridgeController.java @@ -22,7 +22,6 @@ package org.restcomm.connect.mscontrol.mms; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; @@ -82,7 +81,6 @@ public class MmsBridgeController extends MediaServerController { // Logging private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - private final ActorSystem system; // Finite State Machine private final FiniteStateMachine fsm; private final State uninitialized; @@ -116,9 +114,8 @@ public class MmsBridgeController extends MediaServerController { private Sid callSid; - public MmsBridgeController(final ActorRef mrb, final ActorSystem system) { + public MmsBridgeController(final ActorRef mrb) { final ActorRef self = self(); - this.system = system; // Finite states this.uninitialized = new State("uninitialized", null, null); @@ -445,7 +442,7 @@ public UntypedActor create() throws Exception { return new MgcpMediaGroup(mediaGateway, mediaSession, endpoint); } }); - return system.actorOf(props); + return getContext().actorOf(props); } @Override diff --git a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsCallController.java b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsCallController.java index 153ac3d674..0bb3f6d959 100644 --- a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsCallController.java +++ b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsCallController.java @@ -22,7 +22,6 @@ package org.restcomm.connect.mscontrol.mms; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; @@ -154,7 +153,6 @@ public class MmsCallController extends MediaServerController { // TODO rename following variable to 'mediaGateway' private ActorRef mediaGateway; private final ActorRef mrb; - private final ActorSystem system; private MediaGatewayInfo gatewayInfo; private MediaSession session; private ActorRef bridgeEndpoint; @@ -181,10 +179,9 @@ public class MmsCallController extends MediaServerController { private ConnectionIdentifier connectionIdentifier; //public MmsCallController(final List mediaGateways, final Configuration configuration) { - public MmsCallController(final ActorRef mrb, final ActorSystem system) { + public MmsCallController(final ActorRef mrb) { super(); final ActorRef source = self(); - this.system = system; // Initialize the states for the FSM. this.uninitialized = new State("uninitialized", null, null); @@ -315,7 +312,7 @@ public UntypedActor create() throws Exception { return new MgcpMediaGroup(mediaGateway, session, bridgeEndpoint); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private void startRecordingCall() throws Exception { diff --git a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsConferenceController.java b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsConferenceController.java index ec7a10c741..a4199027ce 100644 --- a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsConferenceController.java +++ b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsConferenceController.java @@ -21,11 +21,10 @@ package org.restcomm.connect.mscontrol.mms; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - +import akka.actor.ActorRef; +import akka.event.Logging; +import akka.event.LoggingAdapter; +import jain.protocol.ip.mgcp.message.parms.ConnectionMode; import org.mobicents.servlet.restcomm.mscontrol.messages.MediaServerConferenceControllerStateChanged; import org.restcomm.connect.commons.annotations.concurrency.Immutable; import org.restcomm.connect.commons.dao.Sid; @@ -62,10 +61,10 @@ import org.restcomm.connect.mscontrol.api.messages.StopMediaGroup; import org.restcomm.connect.mscontrol.api.messages.StopRecording; -import akka.actor.ActorRef; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import jain.protocol.ip.mgcp.message.parms.ConnectionMode; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * @author Henrique Rosa (henrique.rosa@telestax.com) diff --git a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsControllerFactory.java b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsControllerFactory.java index f599a48f90..4f160a8293 100644 --- a/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsControllerFactory.java +++ b/restcomm/restcomm.mscontrol.mms/src/main/java/org/restcomm/connect/mscontrol/mms/MmsControllerFactory.java @@ -23,7 +23,6 @@ import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActorFactory; import org.apache.log4j.Logger; @@ -38,15 +37,13 @@ public class MmsControllerFactory implements MediaServerControllerFactory { private static Logger logger = Logger.getLogger(MmsControllerFactory.class); - private final ActorSystem system; private final CallControllerFactory callControllerFactory; private final ConferenceControllerFactory conferenceControllerFactory; private final BridgeControllerFactory bridgeControllerFactory; private final ActorRef mrb; - public MmsControllerFactory(ActorSystem system, ActorRef mrb) { + public MmsControllerFactory(ActorRef mrb) { super(); - this.system = system; this.callControllerFactory = new CallControllerFactory(); this.conferenceControllerFactory = new ConferenceControllerFactory(); this.bridgeControllerFactory = new BridgeControllerFactory(); @@ -54,21 +51,18 @@ public MmsControllerFactory(ActorSystem system, ActorRef mrb) { } @Override - public ActorRef provideCallController() { - final Props props = new Props(this.callControllerFactory); - return system.actorOf(props); + public Props provideCallControllerProps() { + return new Props(this.callControllerFactory); } @Override - public ActorRef provideConferenceController() { - final Props props = new Props(this.conferenceControllerFactory); - return system.actorOf(props); + public Props provideConferenceControllerProps() { + return new Props(this.conferenceControllerFactory); } @Override - public ActorRef provideBridgeController() { - final Props props = new Props(this.bridgeControllerFactory); - return system.actorOf(props); + public Props provideBridgeControllerProps() { + return new Props(this.bridgeControllerFactory); } private final class CallControllerFactory implements UntypedActorFactory { @@ -77,7 +71,7 @@ private final class CallControllerFactory implements UntypedActorFactory { @Override public Actor create() throws Exception { - return new MmsCallController(mrb, system); + return new MmsCallController(mrb); } } @@ -100,7 +94,7 @@ private final class BridgeControllerFactory implements UntypedActorFactory { @Override public Actor create() throws Exception { - return new MmsBridgeController(mrb, system); + return new MmsBridgeController(mrb); } } diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsService.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsService.java index 49622b5027..e58b3815cb 100644 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsService.java +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsService.java @@ -27,13 +27,12 @@ import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; - import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; - import org.apache.commons.configuration.Configuration; import org.joda.time.DateTime; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.UriUtils; import org.restcomm.connect.dao.AccountsDao; import org.restcomm.connect.dao.ApplicationsDao; @@ -54,7 +53,8 @@ import org.restcomm.connect.extension.api.RestcommExtensionException; import org.restcomm.connect.extension.api.RestcommExtensionGeneric; import org.restcomm.connect.extension.controller.ExtensionController; -import org.restcomm.connect.interpreter.SmsInterpreterBuilder; +import org.restcomm.connect.interpreter.SmsInterpreter; +import org.restcomm.connect.interpreter.SmsInterpreterParams; import org.restcomm.connect.interpreter.StartInterpreter; import org.restcomm.connect.monitoringservice.MonitoringService; import org.restcomm.connect.sms.api.CreateSmsSession; @@ -75,7 +75,6 @@ import javax.servlet.sip.SipServletRequest; import javax.servlet.sip.SipServletResponse; import javax.servlet.sip.SipURI; - import java.io.IOException; import java.math.BigDecimal; import java.net.URI; @@ -89,7 +88,7 @@ * @author quintana.thomas@gmail.com (Thomas Quintana) * @author jean.deruelle@telestax.com */ -public final class SmsService extends UntypedActor { +public final class SmsService extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private final ActorSystem system; @@ -291,11 +290,11 @@ private boolean redirectToHostedSmsApp(final ActorRef self, final SipServletRequ URI appUri = number.getSmsUrl(); ActorRef interpreter = null; if (appUri != null || number.getSmsApplicationSid() != null) { - final SmsInterpreterBuilder builder = new SmsInterpreterBuilder(system); + final SmsInterpreterParams.Builder builder = new SmsInterpreterParams.Builder(); builder.setSmsService(self); builder.setConfiguration(configuration); builder.setStorage(storage); - builder.setAccount(number.getAccountSid()); + builder.setAccountId(number.getAccountSid()); builder.setVersion(number.getApiVersion()); final Sid sid = number.getSmsApplicationSid(); if (sid != null) { @@ -315,7 +314,8 @@ private boolean redirectToHostedSmsApp(final ActorRef self, final SipServletRequ builder.setFallbackUrl(UriUtils.resolve(number.getSmsFallbackUrl())); builder.setFallbackMethod(number.getSmsFallbackMethod()); } - interpreter = builder.build(); + final Props props = SmsInterpreter.props(builder.build()); + interpreter = getContext().actorOf(props); } //TODO:do extensions check here too? final ActorRef session = session(this.configuration); @@ -420,7 +420,7 @@ public UntypedActor create() throws Exception { return new SmsSession(p_configuration, sipFactory, outboundInterface(), storage, monitoringService, servletContext); } }); - return system.actorOf(props); + return getContext().actorOf(props); } // used for sending warning and error logs to notification engine and to the console diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsServiceProxy.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsServiceProxy.java index dde5057a78..578b8029e3 100644 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsServiceProxy.java +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsServiceProxy.java @@ -86,7 +86,7 @@ private ActorRef smppService(final Configuration configuration, final SipFactory private static final long serialVersionUID = 1L; @Override public UntypedActor create() throws Exception { - return new SmppService(system, configuration, factory, storage, context, smppMessageHandler); + return new SmppService(configuration, factory, storage, context, smppMessageHandler); } }); return system.actorOf(props); diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java index 4b4cc4f3b2..244a4cba42 100644 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java @@ -20,29 +20,29 @@ package org.restcomm.connect.sms; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import com.cloudhopper.commons.charset.Charset; import com.cloudhopper.commons.charset.CharsetUtil; import com.cloudhopper.commons.util.ByteArrayUtil; -import com.cloudhopper.smpp.tlv.Tlv; import com.cloudhopper.smpp.SmppConstants; +import com.cloudhopper.smpp.tlv.Tlv; import com.google.common.collect.ImmutableMap; import org.apache.commons.configuration.Configuration; -import org.restcomm.connect.sms.api.GetLastSmsRequest; -import org.restcomm.connect.sms.api.SmsSessionAttribute; -import org.restcomm.connect.sms.api.SmsSessionInfo; -import org.restcomm.connect.sms.api.SmsSessionRequest; -import org.restcomm.connect.sms.api.SmsSessionResponse; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.commons.patterns.Observe; +import org.restcomm.connect.commons.patterns.Observing; +import org.restcomm.connect.commons.patterns.StopObserving; import org.restcomm.connect.dao.ClientsDao; import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.dao.RegistrationsDao; import org.restcomm.connect.dao.entities.Client; import org.restcomm.connect.dao.entities.Registration; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.Observing; -import org.restcomm.connect.commons.patterns.StopObserving; +import org.restcomm.connect.sms.api.GetLastSmsRequest; +import org.restcomm.connect.sms.api.SmsSessionAttribute; +import org.restcomm.connect.sms.api.SmsSessionInfo; +import org.restcomm.connect.sms.api.SmsSessionRequest; +import org.restcomm.connect.sms.api.SmsSessionResponse; import org.restcomm.connect.sms.smpp.SmppClientOpsThread; import org.restcomm.connect.sms.smpp.SmppInboundMessageEntity; import org.restcomm.connect.sms.smpp.SmppMessageHandler; @@ -69,7 +69,7 @@ /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class SmsSession extends UntypedActor { +public final class SmsSession extends RestcommUntypedActor { // Logger private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); // Runtime stuff. diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreter.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreter.java index 0a39bc7bdf..b92bb786cd 100644 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreter.java +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreter.java @@ -2,7 +2,6 @@ import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; @@ -20,6 +19,7 @@ import org.apache.log4j.Logger; import org.joda.time.DateTime; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -69,11 +69,9 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import static org.restcomm.connect.interpreter.rcml.Verbs.email; -import static org.restcomm.connect.interpreter.rcml.Verbs.redirect; -import static org.restcomm.connect.interpreter.rcml.Verbs.sms; +import static org.restcomm.connect.interpreter.rcml.Verbs.*; -public class SmppInterpreter extends UntypedActor { +public class SmppInterpreter extends RestcommUntypedActor { private static final int ERROR_NOTIFICATION = 0; @@ -84,7 +82,6 @@ public class SmppInterpreter extends UntypedActor { // private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); // States for the FSM. - private final ActorSystem system; private final State uninitialized; private final State acquiringLastSmsRequest; private final State downloadingRcml; @@ -131,11 +128,8 @@ public class SmppInterpreter extends UntypedActor { private ConcurrentHashMap customHttpHeaderMap = new ConcurrentHashMap(); private ConcurrentHashMap customRequestHeaderMap; - public SmppInterpreter(final ActorRef smppMessageHandler, final Configuration configuration, final DaoManager storage, - final Sid accountId, final String version, final URI url, final String method, final URI fallbackUrl, - final String fallbackMethod) { + public SmppInterpreter(final SmppInterpreterParams params) { super(); - system = context().system(); final ActorRef source = self(); uninitialized = new State("uninitialized", null, null); acquiringLastSmsRequest = new State("acquiring last sms event", new AcquiringLastSmsEvent(source), null); @@ -192,21 +186,30 @@ public SmppInterpreter(final ActorRef smppMessageHandler, final Configuration co // Initialize the FSM. this.fsm = new FiniteStateMachine(uninitialized, transitions); // Initialize the runtime stuff. - this.smppMessageHandler = smppMessageHandler; + this.smppMessageHandler = params.getSmsService(); this.downloader = downloader(); - this.storage = storage; - this.runtime = configuration.subset("runtime-settings"); - this.configuration = configuration.subset("sms-aggregator"); - this.accountId = accountId; - this.version = version; - this.url = url; - this.method = method; - this.fallbackUrl = fallbackUrl; - this.fallbackMethod = fallbackMethod; + this.storage = params.getStorage(); + this.runtime = params.getConfiguration().subset("runtime-settings"); + this.configuration = params.getConfiguration().subset("sms-aggregator"); + this.accountId = params.getAccountId(); + this.version = params.getVersion(); + this.url = params.getUrl(); + this.method = params.getMethod(); + this.fallbackUrl = params.getFallbackUrl(); + this.fallbackMethod = params.getFallbackMethod(); this.sessions = new HashMap(); this.normalizeNumber = runtime.getBoolean("normalize-numbers-for-outbound-calls"); } + public static Props props(final SmppInterpreterParams params) { + return new Props(new UntypedActorFactory() { + @Override + public Actor create() throws Exception { + return new SmppInterpreter(params); + } + }); + } + private ActorRef downloader() { final Props props = new Props(new UntypedActorFactory() { private static final long serialVersionUID = 1L; @@ -215,7 +218,7 @@ public UntypedActor create() throws Exception { return new Downloader(); } }); - return system.actorOf(props); + return getContext().actorOf(props); } ActorRef mailer(final Configuration configuration) { @@ -226,7 +229,7 @@ public Actor create() throws Exception { return new EmailService(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } protected String format(final String number) { @@ -420,7 +423,7 @@ public UntypedActor create() throws Exception { return new Parser(xml, self()); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private void response(final Object message) { diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreterBuilder.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreterBuilder.java deleted file mode 100644 index 6e2279b18d..0000000000 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreterBuilder.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.restcomm.connect.sms.smpp; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorFactory; -import org.apache.commons.configuration.Configuration; -import org.apache.log4j.Logger; -import org.restcomm.connect.commons.dao.Sid; -import org.restcomm.connect.dao.DaoManager; - -import java.net.URI; - -public class SmppInterpreterBuilder { - - private static Logger logger = Logger.getLogger(SmppInterpreterBuilder.class); - private final ActorSystem system; - private Configuration configuration; - private ActorRef service; - private DaoManager storage; - private Sid accountId; - private String version; - private URI url; - private String method; - private URI fallbackUrl; - private String fallbackMethod; - - public SmppInterpreterBuilder(final ActorSystem system) { - super(); - this.system = system; - } - - public ActorRef build() { - final Props props = new Props(new UntypedActorFactory() { - private static final long serialVersionUID = 1L; - - @Override - public UntypedActor create() throws Exception { - return new SmppInterpreter(service, configuration, storage, accountId, version, url, method, fallbackUrl, - fallbackMethod); - } - }); - return system.actorOf(props); - } - - public void setConfiguration(final Configuration configuration) { - this.configuration = configuration; - } - - public void setSmsService(final ActorRef service) { - this.service = service; - } - - public void setStorage(final DaoManager storage) { - this.storage = storage; - } - - public void setAccount(final Sid accountId) { - this.accountId = accountId; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public void setMethod(final String method) { - this.method = method; - } - - public void setFallbackUrl(final URI fallbackUrl) { - this.fallbackUrl = fallbackUrl; - } - - public void setFallbackMethod(final String fallbackMethod) { - this.fallbackMethod = fallbackMethod; - } - - public void setVersion(final String version) { - this.version = version; - } - -} diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreterParams.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreterParams.java new file mode 100644 index 0000000000..a7150a83eb --- /dev/null +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppInterpreterParams.java @@ -0,0 +1,153 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +package org.restcomm.connect.sms.smpp; + +import akka.actor.ActorRef; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.dao.DaoManager; + +import java.net.URI; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public final class SmppInterpreterParams { + + private Configuration configuration; + private ActorRef smsService; + private DaoManager storage; + private Sid accountId; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + + private SmppInterpreterParams(Configuration configuration, ActorRef smsService, DaoManager storage, Sid accountId, String version, URI url, String method, URI fallbackUrl, String fallbackMethod) { + this.configuration = configuration; + this.smsService = smsService; + this.storage = storage; + this.accountId = accountId; + this.version = version; + this.url = url; + this.method = method; + this.fallbackUrl = fallbackUrl; + this.fallbackMethod = fallbackMethod; + } + + public Configuration getConfiguration() { + return configuration; + } + + public ActorRef getSmsService() { + return smsService; + } + + public DaoManager getStorage() { + return storage; + } + + public Sid getAccountId() { + return accountId; + } + + public String getVersion() { + return version; + } + + public URI getUrl() { + return url; + } + + public String getMethod() { + return method; + } + + public URI getFallbackUrl() { + return fallbackUrl; + } + + public String getFallbackMethod() { + return fallbackMethod; + } + + public static final class Builder { + private Configuration configuration; + private ActorRef smsService; + private DaoManager storage; + private Sid accountId; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + + public Builder setConfiguration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + public Builder setSmsService(ActorRef smsService) { + this.smsService = smsService; + return this; + } + + public Builder setStorage(DaoManager storage) { + this.storage = storage; + return this; + } + + public Builder setAccountId(Sid accountId) { + this.accountId = accountId; + return this; + } + + public Builder setVersion(String version) { + this.version = version; + return this; + } + + public Builder setUrl(URI url) { + this.url = url; + return this; + } + + public Builder setMethod(String method) { + this.method = method; + return this; + } + + public Builder setFallbackUrl(URI fallbackUrl) { + this.fallbackUrl = fallbackUrl; + return this; + } + + public Builder setFallbackMethod(String fallbackMethod) { + this.fallbackMethod = fallbackMethod; + return this; + } + + public SmppInterpreterParams build() { + return new SmppInterpreterParams(configuration, smsService, storage, accountId, version, url, method, fallbackUrl, fallbackMethod); + } + } +} diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppMessageHandler.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppMessageHandler.java index a9f826ee02..e00354ca0a 100644 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppMessageHandler.java +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppMessageHandler.java @@ -1,27 +1,25 @@ package org.restcomm.connect.sms.smpp; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; - import com.cloudhopper.commons.charset.CharsetUtil; import com.cloudhopper.smpp.pdu.SubmitSm; +import com.cloudhopper.smpp.tlv.Tlv; import com.cloudhopper.smpp.type.Address; import com.cloudhopper.smpp.type.RecoverablePduException; import com.cloudhopper.smpp.type.SmppChannelException; import com.cloudhopper.smpp.type.SmppInvalidArgumentException; import com.cloudhopper.smpp.type.SmppTimeoutException; import com.cloudhopper.smpp.type.UnrecoverablePduException; -import com.cloudhopper.smpp.tlv.Tlv; import com.google.i18n.phonenumbers.PhoneNumberUtil; - import org.apache.commons.configuration.Configuration; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.UriUtils; import org.restcomm.connect.dao.AccountsDao; import org.restcomm.connect.dao.ApplicationsDao; @@ -29,8 +27,6 @@ import org.restcomm.connect.dao.IncomingPhoneNumbersDao; import org.restcomm.connect.dao.entities.Application; import org.restcomm.connect.dao.entities.IncomingPhoneNumber; -//import org.restcomm.connect.extension.api.ExtensionRequest; -//import org.restcomm.connect.extension.api.ExtensionResponse; import org.restcomm.connect.extension.api.ExtensionType; import org.restcomm.connect.extension.api.IExtensionCreateSmsSessionRequest; import org.restcomm.connect.extension.api.RestcommExtensionException; @@ -48,16 +44,17 @@ import javax.servlet.sip.SipFactory; import javax.servlet.sip.SipServlet; import javax.servlet.sip.SipURI; - import java.io.IOException; import java.net.URI; -import java.util.List; import java.util.Collection; +import java.util.List; + +//import org.restcomm.connect.extension.api.ExtensionRequest; +//import org.restcomm.connect.extension.api.ExtensionResponse; -public class SmppMessageHandler extends UntypedActor { +public class SmppMessageHandler extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - private final ActorSystem system = getContext().system(); private final ServletContext servletContext; private final DaoManager storage; private final Configuration configuration; @@ -160,11 +157,11 @@ private boolean redirectToHostedSmsApp(final ActorRef self, final SmppInboundMes URI appUri = number.getSmsUrl(); - final SmppInterpreterBuilder builder = new SmppInterpreterBuilder(system); + final SmppInterpreterParams.Builder builder = new SmppInterpreterParams.Builder(); builder.setSmsService(self); builder.setConfiguration(configuration); builder.setStorage(storage); - builder.setAccount(number.getAccountSid()); + builder.setAccountId(number.getAccountSid()); builder.setVersion(number.getApiVersion()); final Sid sid = number.getSmsApplicationSid(); if (sid != null) { @@ -182,7 +179,8 @@ private boolean redirectToHostedSmsApp(final ActorRef self, final SmppInboundMes builder.setFallbackUrl(UriUtils.resolve(number.getSmsFallbackUrl())); builder.setFallbackMethod(number.getSmsFallbackMethod()); } - interpreter = builder.build(); + final Props props = SmppInterpreter.props(builder.build()); + interpreter = getContext().actorOf(props); Configuration cfg = this.configuration; //Extension final ActorRef session = session(cfg); @@ -221,7 +219,7 @@ public UntypedActor create() throws Exception { return new SmsSession(p_configuration, sipFactory, outboundInterface(), storage, monitoringService, servletContext); } }); - return system.actorOf(props); + return getContext().actorOf(props); } public void outbound(SmppOutboundMessageEntity request) throws SmppInvalidArgumentException, IOException { diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppService.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppService.java index aa17a989fc..1851a63029 100644 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppService.java +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/smpp/SmppService.java @@ -20,8 +20,20 @@ package org.restcomm.connect.sms.smpp; -import static javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES; +import akka.actor.ActorRef; +import akka.event.Logging; +import akka.event.LoggingAdapter; +import com.cloudhopper.smpp.SmppBindType; +import com.cloudhopper.smpp.impl.DefaultSmppClient; +import com.cloudhopper.smpp.type.Address; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.dao.DaoManager; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.sip.SipFactory; +import javax.servlet.sip.SipURI; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; @@ -30,23 +42,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.atomic.AtomicInteger; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.sip.SipFactory; -import javax.servlet.sip.SipURI; - -import akka.actor.ActorRef; -import org.apache.commons.configuration.Configuration; -import org.restcomm.connect.dao.DaoManager; - -import akka.actor.ActorSystem; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; - -import com.cloudhopper.smpp.SmppBindType; -import com.cloudhopper.smpp.impl.DefaultSmppClient; -import com.cloudhopper.smpp.type.Address; +import static javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES; /** * @@ -54,10 +50,9 @@ * @author gvagenas@telestax.com * */ -public final class SmppService extends UntypedActor { +public final class SmppService extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - private final ActorSystem system; private final ActorRef smppMessageHandler; private final Configuration configuration; private boolean authenticateUsers = true; @@ -82,11 +77,10 @@ public final class SmppService extends UntypedActor { private ArrayList smppList = new ArrayList(); - public SmppService(final ActorSystem system, final Configuration configuration, final SipFactory factory, + public SmppService(final Configuration configuration, final SipFactory factory, final DaoManager storage, final ServletContext servletContext, final ActorRef smppMessageHandler) { super(); - this.system = system; this.smppMessageHandler = smppMessageHandler; this.configuration = configuration; final Configuration runtime = configuration.subset("runtime-settings"); diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Bridge.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Bridge.java index ef3fd27331..ac8a5de59b 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Bridge.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Bridge.java @@ -21,19 +21,19 @@ package org.restcomm.connect.telephony; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.restcomm.connect.telephony.api.BridgeStateChanged; -import org.restcomm.connect.telephony.api.JoinCalls; -import org.restcomm.connect.telephony.api.StartBridge; -import org.restcomm.connect.telephony.api.StopBridge; +import akka.actor.ActorRef; +import akka.event.Logging; +import akka.event.LoggingAdapter; +import jain.protocol.ip.mgcp.message.parms.ConnectionMode; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; import org.restcomm.connect.commons.fsm.Transition; +import org.restcomm.connect.commons.patterns.Observe; +import org.restcomm.connect.commons.patterns.Observing; +import org.restcomm.connect.commons.patterns.StopObserving; +import org.restcomm.connect.mscontrol.api.MediaServerControllerFactory; import org.restcomm.connect.mscontrol.api.messages.CreateMediaSession; import org.restcomm.connect.mscontrol.api.messages.JoinCall; import org.restcomm.connect.mscontrol.api.messages.JoinComplete; @@ -42,22 +42,22 @@ import org.restcomm.connect.mscontrol.api.messages.MediaServerControllerStateChanged.MediaServerControllerState; import org.restcomm.connect.mscontrol.api.messages.StartRecording; import org.restcomm.connect.mscontrol.api.messages.Stop; -import org.restcomm.connect.commons.patterns.Observe; -import org.restcomm.connect.commons.patterns.Observing; -import org.restcomm.connect.commons.patterns.StopObserving; +import org.restcomm.connect.telephony.api.BridgeStateChanged; import org.restcomm.connect.telephony.api.BridgeStateChanged.BridgeState; +import org.restcomm.connect.telephony.api.JoinCalls; +import org.restcomm.connect.telephony.api.StartBridge; +import org.restcomm.connect.telephony.api.StopBridge; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import jain.protocol.ip.mgcp.message.parms.ConnectionMode; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * @author Henrique Rosa (henrique.rosa@telestax.com) * */ -public class Bridge extends UntypedActor { +public class Bridge extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); @@ -83,11 +83,11 @@ public class Bridge extends UntypedActor { // Observer pattern private final List observers; - public Bridge(final ActorRef mscontroller) { + public Bridge(MediaServerControllerFactory factory) { final ActorRef source = self(); // Media Server Controller - this.mscontroller = mscontroller; + this.mscontroller = getContext().actorOf(factory.provideBridgeControllerProps()); // States for the FSM this.uninitialized = new State("uninitialized", null, null); diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/BridgeManager.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/BridgeManager.java index 18d032eb4b..ecb6e87d7e 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/BridgeManager.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/BridgeManager.java @@ -22,12 +22,12 @@ package org.restcomm.connect.telephony; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.patterns.Observe; import org.restcomm.connect.mscontrol.api.MediaServerControllerFactory; import org.restcomm.connect.telephony.api.BridgeManagerResponse; @@ -38,17 +38,15 @@ * @author Henrique Rosa (henrique.rosa@telestax.com) * */ -public class BridgeManager extends UntypedActor { +public class BridgeManager extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private final MediaServerControllerFactory factory; - private final ActorSystem system; public BridgeManager(final MediaServerControllerFactory factory) { super(); this.factory = factory; - this.system = context().system(); } private ActorRef createBridge() { @@ -57,10 +55,10 @@ private ActorRef createBridge() { @Override public UntypedActor create() throws Exception { - return new Bridge(factory.provideBridgeController()); + return new Bridge(factory); } }); - return system.actorOf(props); + return getContext().actorOf(props); } /* diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java index a4bbf71749..3fd44d5d12 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java @@ -20,7 +20,6 @@ package org.restcomm.connect.telephony; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.ReceiveTimeout; import akka.actor.UntypedActor; @@ -28,7 +27,6 @@ import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; - import org.apache.commons.configuration.Configuration; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; @@ -40,6 +38,7 @@ import org.restcomm.connect.commons.annotations.concurrency.Immutable; import org.restcomm.connect.commons.configuration.RestcommConfiguration; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -57,6 +56,7 @@ import org.restcomm.connect.dao.entities.CallDetailRecord; import org.restcomm.connect.http.client.Downloader; import org.restcomm.connect.http.client.HttpRequestDescriptor; +import org.restcomm.connect.mscontrol.api.MediaServerControllerFactory; import org.restcomm.connect.mscontrol.api.messages.CloseMediaSession; import org.restcomm.connect.mscontrol.api.messages.Collect; import org.restcomm.connect.mscontrol.api.messages.CreateMediaSession; @@ -95,7 +95,6 @@ import org.restcomm.connect.telephony.api.InitializeOutbound; import org.restcomm.connect.telephony.api.Reject; import org.restcomm.connect.telephony.api.RemoveParticipant; - import scala.concurrent.duration.Duration; import javax.sdp.SdpException; @@ -113,7 +112,6 @@ import javax.sip.header.RecordRouteHeader; import javax.sip.header.RouteHeader; import javax.sip.message.Response; - import java.io.IOException; import java.math.BigDecimal; import java.net.InetAddress; @@ -142,7 +140,7 @@ * */ @Immutable -public final class Call extends UntypedActor { +public final class Call extends RestcommUntypedActor { // Logging private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); @@ -267,7 +265,6 @@ public final class Call extends UntypedActor { private HttpRequestDescriptor requestCallback; ActorRef downloader = null; - ActorSystem system = null; private URI statusCallback; private String statusCallbackMethod; private List statusCallbackEvent; @@ -286,18 +283,17 @@ public String toString() { } }; - public Call(final SipFactory factory, final ActorRef mediaSessionController, final Configuration configuration, + public Call(final SipFactory factory, final MediaServerControllerFactory mediaSessionControllerFactory, final Configuration configuration, final URI statusCallback, final String statusCallbackMethod, final List statusCallbackEvent) { - this(factory, mediaSessionController, configuration, statusCallback, statusCallbackMethod, + this(factory, mediaSessionControllerFactory, configuration, statusCallback, statusCallbackMethod, statusCallbackEvent, null); } - public Call(final SipFactory factory, final ActorRef mediaSessionController, final Configuration configuration, + public Call(final SipFactory factory, final MediaServerControllerFactory mediaSessionControllerFactory, final Configuration configuration, final URI statusCallback, final String statusCallbackMethod, final List statusCallbackEvent, Map> headers) { super(); final ActorRef source = self(); - this.system = context().system(); this.statusCallback = statusCallback; this.statusCallbackMethod = statusCallbackMethod; this.statusCallbackEvent = statusCallbackEvent; @@ -409,7 +405,7 @@ public Call(final SipFactory factory, final ActorRef mediaSessionController, fin this.conferencing = false; // Media Session Control runtime stuff. - this.msController = mediaSessionController; + this.msController = getContext().actorOf(mediaSessionControllerFactory.provideCallControllerProps()); this.fail = false; // Initialize the runtime stuff. @@ -441,7 +437,7 @@ public UntypedActor create() throws Exception { return new Downloader(); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private boolean is(State state) { diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManager.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManager.java index eb1d0a5042..46c37fe15c 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManager.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManager.java @@ -39,6 +39,7 @@ import org.joda.time.DateTime; import org.restcomm.connect.commons.configuration.RestcommConfiguration; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.patterns.StopObserving; import org.restcomm.connect.commons.telephony.CreateCallType; import org.restcomm.connect.commons.telephony.ProxyRule; @@ -66,7 +67,8 @@ import org.restcomm.connect.extension.controller.ExtensionController; import org.restcomm.connect.interpreter.StartInterpreter; import org.restcomm.connect.interpreter.StopInterpreter; -import org.restcomm.connect.interpreter.VoiceInterpreterBuilder; +import org.restcomm.connect.interpreter.VoiceInterpreter; +import org.restcomm.connect.interpreter.VoiceInterpreterParams; import org.restcomm.connect.monitoringservice.MonitoringService; import org.restcomm.connect.mscontrol.api.MediaServerControllerFactory; import org.restcomm.connect.telephony.api.CallInfo; @@ -125,12 +127,7 @@ import static akka.pattern.Patterns.ask; import static javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES; -import static javax.servlet.sip.SipServletResponse.SC_ACCEPTED; -import static javax.servlet.sip.SipServletResponse.SC_BAD_REQUEST; -import static javax.servlet.sip.SipServletResponse.SC_FORBIDDEN; -import static javax.servlet.sip.SipServletResponse.SC_NOT_FOUND; -import static javax.servlet.sip.SipServletResponse.SC_OK; -import static javax.servlet.sip.SipServletResponse.SC_SERVER_INTERNAL_ERROR; +import static javax.servlet.sip.SipServletResponse.*; /** * @author quintana.thomas@gmail.com (Thomas Quintana) @@ -138,7 +135,7 @@ * @author jean.deruelle@telestax.com * @author gvagenas@telestax.com */ -public final class CallManager extends UntypedActor { +public final class CallManager extends RestcommUntypedActor { static final int ERROR_NOTIFICATION = 0; static final int WARNING_NOTIFICATION = 1; @@ -372,7 +369,7 @@ private ActorRef call(final CreateCall request) { @Override public UntypedActor create() throws Exception { - return new Call(sipFactory, msControllerFactory.provideCallController(), configuration, + return new Call(sipFactory, msControllerFactory, configuration, null, null, null, null); } }); @@ -382,12 +379,12 @@ public UntypedActor create() throws Exception { @Override public UntypedActor create() throws Exception { - return new Call(sipFactory, msControllerFactory.provideCallController(), configuration, + return new Call(sipFactory, msControllerFactory, configuration, request.statusCallback(), request.statusCallbackMethod(), request.statusCallbackEvent(), request.getOutboundProxyHeaders()); } }); } - return system.actorOf(props); + return getContext().actorOf(props); } private boolean check(final Object message) throws IOException { @@ -413,7 +410,7 @@ private void destroy(final Object message) throws Exception { if(logger.isInfoEnabled()) { logger.info("About to destroy call: "+request.call().path()+", call isTerminated(): "+sender().isTerminated()+", sender: "+sender()); } - system.stop(call); + getContext().stop(call); } } @@ -818,11 +815,11 @@ private void processRequestAndProxyOut (final SipServletRequest request, final C rcml = String.format("%s", sipUri); } - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self()); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); @@ -843,7 +840,8 @@ private void processRequestAndProxyOut (final SipServletRequest request, final C builder.setEmailAddress(account.getEmailAddress()); builder.setRcml(rcml); builder.setMonitoring(monitoring); - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); final ActorRef call = call(null); final SipApplicationSession application = request.getApplicationSession(); application.setAttribute(Call.class.getName(), call); @@ -858,11 +856,11 @@ private void processRequestAndProxyOut (final SipServletRequest request, final C private void proxyThroughMediaServerAsNumber (final SipServletRequest request, final Client client, final String destNumber) { String rcml = ""+destNumber+""; - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self()); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); builder.setAccount(client.getAccountSid()); @@ -871,7 +869,9 @@ private void proxyThroughMediaServerAsNumber (final SipServletRequest request, f builder.setEmailAddress(account.getEmailAddress()); builder.setRcml(rcml); builder.setMonitoring(monitoring); - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); + final ActorRef call = call(null); final SipApplicationSession application = request.getApplicationSession(); application.setAttribute(Call.class.getName(), call); @@ -881,11 +881,11 @@ private void proxyThroughMediaServerAsNumber (final SipServletRequest request, f private void proxyDialClientThroughMediaServer(final SipServletRequest request, final Client client, final String destNumber) { String rcml = ""+destNumber+""; - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self()); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); builder.setAccount(client.getAccountSid()); @@ -894,7 +894,9 @@ private void proxyDialClientThroughMediaServer(final SipServletRequest request, builder.setEmailAddress(account.getEmailAddress()); builder.setRcml(rcml); builder.setMonitoring(monitoring); - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); + final ActorRef call = call(null); final SipApplicationSession application = request.getApplicationSession(); application.setAttribute(Call.class.getName(), call); @@ -1110,11 +1112,11 @@ private void transfer(SipServletRequest request) throws Exception { existingInterpreter.tell(new StopInterpreter(true), null); // Build a new VoiceInterpreter - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self()); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); builder.setAccount(cdr.getAccountSid()); @@ -1139,7 +1141,8 @@ private void transfer(SipServletRequest request) throws Exception { builder.setMonitoring(monitoring); // Ask first transferorActor leg to execute with the new Interpreter - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); system.scheduler().scheduleOnce(Duration.create(500, TimeUnit.MILLISECONDS), interpreter, new StartInterpreter(transfereeActor), system.dispatcher()); if(logger.isInfoEnabled()) { @@ -1207,11 +1210,11 @@ private boolean redirectToHostedVoiceApp(final ActorRef self, final SipServletRe number = numbers.getIncomingPhoneNumber("*"); } if (number != null) { - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); //https://github.com/RestComm/Restcomm-Connect/issues/1939 @@ -1245,7 +1248,9 @@ private boolean redirectToHostedVoiceApp(final ActorRef self, final SipServletRe builder.setStatusCallback(number.getStatusCallback()); builder.setStatusCallbackMethod(number.getStatusCallbackMethod()); builder.setMonitoring(monitoring); - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); + final ActorRef call = call(null); final SipApplicationSession application = request.getApplicationSession(); application.setAttribute(Call.class.getName(), call); @@ -1290,11 +1295,11 @@ private boolean redirectToClientVoiceApp(final ActorRef self, final SipServletRe boolean isClientManaged =( (applicationSid != null && !applicationSid.toString().isEmpty() && !applicationSid.toString().equals("")) || (clientAppVoiceUrl != null && !clientAppVoiceUrl.toString().isEmpty() && !clientAppVoiceUrl.toString().equals(""))); if (isClientManaged) { - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); builder.setAccount(client.getAccountSid()); @@ -1311,7 +1316,8 @@ private boolean redirectToClientVoiceApp(final ActorRef self, final SipServletRe builder.setFallbackUrl(null); builder.setFallbackMethod(client.getVoiceFallbackMethod()); builder.setMonitoring(monitoring); - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); final ActorRef call = call(null); final SipApplicationSession application = request.getApplicationSession(); application.setAttribute(Call.class.getName(), call); @@ -1547,11 +1553,11 @@ private boolean isLBPatchRURI(SipServletRequest request, private void execute(final Object message) { final ExecuteCallScript request = (ExecuteCallScript) message; final ActorRef self = self(); - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); builder.setAccount(request.account()); @@ -1561,7 +1567,8 @@ private void execute(final Object message) { builder.setFallbackUrl(request.fallbackUrl()); builder.setFallbackMethod(request.fallbackMethod()); builder.setMonitoring(monitoring); - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); interpreter.tell(new StartInterpreter(request.call()), self); } @@ -1629,11 +1636,11 @@ private void update(final Object message) throws Exception { existingInterpreter.tell(new StopInterpreter(true), null); // Build a new VoiceInterpreter - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); builder.setAccount(request.account()); @@ -1645,9 +1652,10 @@ private void update(final Object message) throws Exception { builder.setStatusCallback(request.callback()); builder.setStatusCallbackMethod(request.callbackMethod()); builder.setMonitoring(monitoring); + final Props props = VoiceInterpreter.props(builder.build()); // Ask first call leg to execute with the new Interpreter - final ActorRef interpreter = builder.build(); + final ActorRef interpreter = getContext().actorOf(props); system.scheduler().scheduleOnce(Duration.create(500, TimeUnit.MILLISECONDS), interpreter, new StartInterpreter(request.call()), system.dispatcher()); // interpreter.tell(new StartInterpreter(request.call()), self); @@ -1658,7 +1666,7 @@ private void update(final Object message) throws Exception { // Check what to do with the second/outbound call leg of the call if (relatedCall != null && listOfRelatedCalls == null) { if (moveConnectedCallLeg) { - final ActorRef relatedInterpreter = builder.build(); + final ActorRef relatedInterpreter = getContext().actorOf(props); if(logger.isInfoEnabled()) { logger.info("About to redirect related Call :" + relatedCall.path() + " with 200ms delay to related interpreter: " + relatedInterpreter.path()); @@ -2396,11 +2404,11 @@ private void imsProxyThroughMediaServer(final SipServletRequest request, final C logger.info("rcml: " + rcml); } - final VoiceInterpreterBuilder builder = new VoiceInterpreterBuilder(system); + final VoiceInterpreterParams.Builder builder = new VoiceInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); builder.setCallManager(self()); - builder.setConferenceManager(conferences); + builder.setConferenceCenter(conferences); builder.setBridgeManager(bridges); builder.setSmsService(sms); builder.setAccount(Sid.generate(Sid.Type.ACCOUNT,imsAccount)); @@ -2412,7 +2420,8 @@ private void imsProxyThroughMediaServer(final SipServletRequest request, final C builder.setImsUaLogin(user); builder.setImsUaPassword(password); } - final ActorRef interpreter = builder.build(); + final Props props = VoiceInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); final ActorRef call = call(null); final SipApplicationSession application = request.getApplicationSession(); application.setAttribute(Call.class.getName(), call); diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManagerProxy.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManagerProxy.java index 4f4f1dfa42..e4e9db04cc 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManagerProxy.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/CallManagerProxy.java @@ -128,14 +128,13 @@ public UntypedActor create() throws Exception { return system.actorOf(props); } - private ActorRef ussdManager(final Configuration configuration, final ServletContext context, final ActorRef conferences, - final ActorRef bridges, final ActorRef sms, final SipFactory factory, final DaoManager storage) { + private ActorRef ussdManager(final Configuration configuration, final ServletContext context, final SipFactory factory, final DaoManager storage) { final Props props = new Props(new UntypedActorFactory() { private static final long serialVersionUID = 1L; @Override public UntypedActor create() throws Exception { - return new UssdCallManager(system, configuration, context, conferences, sms, factory, storage); + return new UssdCallManager(configuration, context, factory, storage); } }); return system.actorOf(props); @@ -200,7 +199,7 @@ public void servletInitialized(SipServletContextEvent event) { final ActorRef bridges = bridges(mscontrolFactory); final ActorRef sms = (ActorRef) context.getAttribute(SmsService.class.getName()); manager = manager(configuration, context, mscontrolFactory, conferences, bridges, sms, factory, storage); - ussdManager = ussdManager(configuration, context, conferences, bridges, sms, factory, storage); + ussdManager = ussdManager(configuration, context, factory, storage); context.setAttribute(CallManager.class.getName(), manager); context.setAttribute(UssdCallManager.class.getName(), ussdManager); } diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Conference.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Conference.java index 1fe597f423..4ee6946c12 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Conference.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Conference.java @@ -20,13 +20,13 @@ package org.restcomm.connect.telephony; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import jain.protocol.ip.mgcp.message.parms.ConnectionMode; import org.mobicents.servlet.restcomm.mscontrol.messages.MediaServerConferenceControllerStateChanged; import org.restcomm.connect.commons.annotations.concurrency.Immutable; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -38,6 +38,7 @@ import org.restcomm.connect.dao.ConferenceDetailRecordsDao; import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.dao.entities.ConferenceDetailRecord; +import org.restcomm.connect.mscontrol.api.MediaServerControllerFactory; import org.restcomm.connect.mscontrol.api.messages.CreateMediaSession; import org.restcomm.connect.mscontrol.api.messages.JoinCall; import org.restcomm.connect.mscontrol.api.messages.JoinComplete; @@ -72,7 +73,7 @@ * @author maria.farooq@telestax.com (Maria Farooq) */ @Immutable -public final class Conference extends UntypedActor { +public final class Conference extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); @@ -107,7 +108,7 @@ public final class Conference extends UntypedActor { private final ActorRef conferenceCenter; - public Conference(final String name, final ActorRef msController, final DaoManager storage, final ActorRef conferenceCenter) { + public Conference(final String name, final MediaServerControllerFactory factory, final DaoManager storage, final ActorRef conferenceCenter) { super(); final ActorRef source = self(); @@ -150,7 +151,7 @@ public Conference(final String name, final ActorRef msController, final DaoManag this.conferenceCenter = conferenceCenter; //generate it later at MRB level, by watching if same conference is running on another RC instance. //this.sid = Sid.generate(Sid.Type.CONFERENCE); - this.mscontroller = msController; + this.mscontroller = getContext().actorOf(factory.provideConferenceControllerProps()); this.calls = new ArrayList(); this.observers = new ArrayList(); } diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ConferenceCenter.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ConferenceCenter.java index 2c88516de7..9fa9aa1b4a 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ConferenceCenter.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ConferenceCenter.java @@ -20,13 +20,13 @@ package org.restcomm.connect.telephony; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.patterns.Observe; import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.mscontrol.api.MediaServerControllerFactory; @@ -46,7 +46,7 @@ * @author amit.bhayani@telestax.com (Amit Bhayani) * @author maria.farooq@telestax.com (Maria Farooq) */ -public final class ConferenceCenter extends UntypedActor { +public final class ConferenceCenter extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); @@ -54,7 +54,6 @@ public final class ConferenceCenter extends UntypedActor { private final Map conferences; private final Map> initializing; private final DaoManager storage; - private final ActorSystem system; public ConferenceCenter(final MediaServerControllerFactory factory, final DaoManager storage) { super(); @@ -62,7 +61,6 @@ public ConferenceCenter(final MediaServerControllerFactory factory, final DaoMan this.conferences = new HashMap(); this.initializing = new HashMap>(); this.storage = storage; - this.system = context().system(); } private ActorRef getConference(final String name) { @@ -72,10 +70,10 @@ private ActorRef getConference(final String name) { @Override public UntypedActor create() throws Exception { //Here Here we can pass Gateway where call is connected - return new Conference(name, factory.provideConferenceController(), storage, self()); + return new Conference(name, factory, storage, getSelf()); } }); - return system.actorOf(props); + return getContext().actorOf(props); } @Override diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/proxy/ProxyManager.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/proxy/ProxyManager.java index 1809570ec7..f7e1f243e4 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/proxy/ProxyManager.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/proxy/ProxyManager.java @@ -19,13 +19,17 @@ */ package org.restcomm.connect.telephony.proxy; -import static javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES; -import static javax.servlet.sip.SipServletResponse.SC_OK; -import static javax.servlet.sip.SipServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED; -import static javax.servlet.sip.SipServletResponse.SC_UNAUTHORIZED; - -import java.util.List; -import java.util.concurrent.TimeUnit; +import akka.actor.ActorContext; +import akka.actor.ReceiveTimeout; +import akka.event.Logging; +import akka.event.LoggingAdapter; +import org.joda.time.DateTime; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.dao.DaoManager; +import org.restcomm.connect.dao.GatewaysDao; +import org.restcomm.connect.dao.entities.Gateway; +import org.restcomm.connect.telephony.api.RegisterGateway; +import scala.concurrent.duration.Duration; import javax.servlet.ServletContext; import javax.servlet.sip.Address; @@ -37,25 +41,17 @@ import javax.servlet.sip.SipServletResponse; import javax.servlet.sip.SipSession; import javax.servlet.sip.SipURI; +import java.util.List; +import java.util.concurrent.TimeUnit; -import org.joda.time.DateTime; -import org.restcomm.connect.dao.DaoManager; -import org.restcomm.connect.dao.GatewaysDao; -import org.restcomm.connect.dao.entities.Gateway; -import org.restcomm.connect.telephony.api.RegisterGateway; - -import scala.concurrent.duration.Duration; -import akka.actor.ActorContext; -import akka.actor.ReceiveTimeout; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; +import static javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES; +import static javax.servlet.sip.SipServletResponse.*; /** * @author quintana.thomas@gmail.com (Thomas Quintana) * @author gvagenas@gmail.com */ -public final class ProxyManager extends UntypedActor { +public final class ProxyManager extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private static final int ttl = 1800; diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ua/UserAgentManager.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ua/UserAgentManager.java index ccb3b01982..c5c0cd7512 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ua/UserAgentManager.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/ua/UserAgentManager.java @@ -21,13 +21,13 @@ import akka.actor.ActorRef; import akka.actor.ReceiveTimeout; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import org.apache.commons.configuration.Configuration; import org.joda.time.DateTime; import org.restcomm.connect.commons.configuration.RestcommConfiguration; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.DigestAuthentication; import org.restcomm.connect.dao.ClientsDao; import org.restcomm.connect.dao.DaoManager; @@ -61,16 +61,14 @@ import static java.lang.Integer.parseInt; import static javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES; -import static javax.servlet.sip.SipServletResponse.SC_OK; -import static javax.servlet.sip.SipServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED; -import static javax.servlet.sip.SipServletResponse.SC_UNAUTHORIZED; +import static javax.servlet.sip.SipServletResponse.*; import static org.restcomm.connect.commons.util.HexadecimalUtils.toHex; /** * @author quintana.thomas@gmail.com (Thomas Quintana) * @author jean.deruelle@telestax.com */ -public final class UserAgentManager extends UntypedActor { +public final class UserAgentManager extends RestcommUntypedActor { private static final int DEFAUL_IMS_PROXY_PORT = -1; private static final String REGISTER = "REGISTER"; private static final String REQ_PARAMETER = "Req"; diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/faultTolerance/ActorFaultToleranceTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/faultTolerance/ActorFaultToleranceTest.java deleted file mode 100644 index 315180ff9b..0000000000 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/faultTolerance/ActorFaultToleranceTest.java +++ /dev/null @@ -1,212 +0,0 @@ -package org.restcomm.connect.testsuite.faultTolerance; - -import akka.actor.ActorPath; -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; -import akka.testkit.JavaTestKit; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import scala.concurrent.duration.Duration; - -import static akka.pattern.Patterns.ask; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Created by gvagenas on 22/02/2017. - */ -public class ActorFaultToleranceTest { - - static ActorSystem system; - - @BeforeClass - public static void setup () { - Config config = ConfigFactory.load("akka_fault_tolerance_application.conf"); - system = ActorSystem.create("test", config ); - System.out.println(system.settings()); - } - - @AfterClass - public static void teardown () { - system.shutdown(); - } - - @Test - public void testIt () { - /* - * Wrap the whole test procedure within a testkit constructor - * if you want to receive actor replies or use Within(), etc. - */ - new JavaTestKit(system) {{ - final Props props = new Props(TestActor.class); - final ActorRef subject = system.actorOf(props); - - // can also use JavaTestKit “from the outside” - final JavaTestKit probe = new JavaTestKit(system); - // “inject” the probe by passing it to the test subject - // like a real resource would be passed in production - subject.tell(probe.getRef(), getRef()); - // await the correct response - expectMsgEquals(duration("1 second"), "done"); - - // the run() method needs to finish within 3 seconds - new Within(duration("3 seconds")) { - protected void run () { - - subject.tell("hello", getRef()); - - // This is a demo: would normally use expectMsgEquals(). - // Wait time is bounded by 3-second deadline above. - new AwaitCond() { - protected boolean cond () { - return probe.msgAvailable(); - } - }; - - // response must have been enqueued to us before probe - expectMsgEquals(Duration.Zero(), "world"); - // check that the probe we injected earlier got the msg - probe.expectMsgEquals(Duration.Zero(), "hello"); - assertEquals(getRef(), probe.getLastSender()); - - // Will wait for the rest of the 3 seconds - expectNoMsg(); - } - }; - }}; - } - - @Test - public void testException () throws Exception { - new JavaTestKit(system) {{ - LoggingAdapter logger = Logging.getLogger(system, this); - - final ActorRef subject = system.actorOf(new Props(TestActor.class)); - - subject.tell("exceptionMsgReceived", getRef()); - expectMsgEquals(duration("1 second"), false); - - ActorPath subjectPath = subject.path(); - int subjectHashCode = subject.hashCode(); - subject.tell("exception", getRef()); - expectMsgEquals(duration("1 second"), "I don't stop on exceptions"); - Thread.sleep(5000); - - //Verify Actor didn't restarted, if exceptionMsgReceived is TRUE that means the actor DID NOT restarted - subject.tell("exceptionMsgReceived", getRef()); - expectMsgEquals(duration("1 second"), true); - - system.stop(subject); - Thread.sleep(500); - assertTrue(subject.isTerminated()); - }}; - } - - @Test - public void testExceptionOnAchildActor () throws Exception { - new JavaTestKit(system) {{ - LoggingAdapter logger = Logging.getLogger(system, this); - - final ActorRef subject = system.actorOf(new Props(TestActor.class)); - - final ActorRef childActor = system.actorOf(new Props(TestActor2.class)); - - childActor.tell("exceptionMsgReceived", getRef()); - expectMsgEquals(duration("1 second"), false); - - childActor.tell("exception", getRef()); - ActorPath subjectPath = childActor.path(); - expectMsgEquals(duration("1 second"), "Me the TestActor2, I don't stop on exceptions"); - - //Verify Actor didn't restarted, if exceptionMsgReceived is TRUE that means the actor DID NOT restarted - Thread.sleep(5000); - childActor.tell("exceptionMsgReceived", getRef()); - expectMsgEquals(duration("1 second"), true); - }}; - } - - public static class TestActor extends UntypedActor { - - private LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - ActorRef target = null; - boolean exceptionMsgReceived = false; - - public void onReceive (Object msg) { - final Class klass = msg.getClass(); - logger.info(" ********** TestActor " + self().path() + " Processing Message: " + klass.getName()); - - if (msg.equals("hello")) { - getSender().tell("world", getSelf()); - if (target != null) target.forward(msg, getContext()); - - } else if (msg.equals("exception")) { - exceptionMsgReceived = true; - getSender().tell("I don't stop on exceptions", getSelf()); - String s = null; - s.equalsIgnoreCase("blabla"); - } else if (msg.equals("exceptionMsgReceived")) { - sender().tell(exceptionMsgReceived, self()); - } else if (msg.equals("CreateChild")) { - final Props props = new Props(TestActor2.class); - final ActorRef actor2 = system.actorOf(props); - getSender().tell(actor2, self()); - } else if (msg instanceof ActorRef) { - target = (ActorRef) msg; - getSender().tell("done", getSelf()); - } - } - - @Override - public void postStop () { - logger.info("At postStop method"); - super.postStop(); - } - - @Override - public void postRestart (Throwable reason) { - logger.info("At postRestart method"); - super.postRestart(reason); - } - } - - public static class TestActor2 extends UntypedActor { - - private LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - ActorRef target = null; - boolean exceptionMsgReceived = false; - - public void onReceive (Object msg) { - final Class klass = msg.getClass(); - logger.info(" ********** TestActor2 " + self().path() + " Processing Message: " + klass.getName()); - - if (msg.equals("exception")) { - exceptionMsgReceived = true; - getSender().tell("Me the TestActor2, I don't stop on exceptions", getSelf()); - String s = null; - s.equalsIgnoreCase("blabla"); - } else if (msg.equals("exceptionMsgReceived")) { - sender().tell(exceptionMsgReceived, self()); - } - } - - @Override - public void postStop () { - logger.info("TestActor2, at postStop method"); - super.postStop(); - } - - @Override - public void postRestart (Throwable reason) { - logger.info("TestActor2, at postRestart method"); - super.postRestart(reason); - } - } -} diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/faultTolerance/ActorSupervisorStrategyTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/faultTolerance/ActorSupervisorStrategyTest.java new file mode 100644 index 0000000000..a411c1bcb5 --- /dev/null +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/faultTolerance/ActorSupervisorStrategyTest.java @@ -0,0 +1,110 @@ +package org.restcomm.connect.testsuite.faultTolerance; + +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.Props; +import akka.testkit.JavaTestKit; +import akka.util.Timeout; +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import scala.concurrent.Await; +import scala.concurrent.Future; +import scala.concurrent.duration.Duration; + +import java.util.concurrent.TimeUnit; + +import static akka.pattern.Patterns.ask; +import static org.junit.Assert.assertTrue; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public class ActorSupervisorStrategyTest { + + static ActorSystem system; + + @BeforeClass + public static void setup() { + Config config = ConfigFactory.load("akka_fault_tolerance_application.conf"); + system = ActorSystem.create("test", config); + } + + @AfterClass + public static void teardown() { + system.shutdown(); + } + + @Test + public void parentActorThrowsExceptionTest() throws Exception { + new JavaTestKit(system) {{ + final ActorRef parent = system.actorOf(new Props(Parent.class)); + parent.tell("check exception", getRef()); + expectMsgEquals(duration("1 second"), false); + parent.tell("throw exception", getRef()); + Thread.sleep(5000); + parent.tell("check exception", getRef()); + expectMsgEquals(duration("1 second"), true); + }}; + } + + @Test + public void childActorThrowsExceptionTest() throws Exception { + new JavaTestKit(system) {{ + final ActorRef parent = system.actorOf(new Props(Parent.class)); + final Future future = ask(parent, "create child", new Timeout(Duration.create(5, TimeUnit.SECONDS))); + final ActorRef child = (ActorRef) Await.result(future, Duration.create(10, TimeUnit.SECONDS)); + + child.tell("check exception", getRef()); + expectMsgEquals(duration("1 second"), false); + child.tell("throw exception", getRef()); + Thread.sleep(5000); + child.tell("check exception", getRef()); + expectMsgEquals(duration("1 second"), true); + + system.stop(parent); + Thread.sleep(500); + assertTrue(parent.isTerminated()); + assertTrue(child.isTerminated()); + }}; + + } + + public static class Parent extends RestcommUntypedActor { + + private boolean receivedThrowException; + + @SuppressWarnings("Duplicates") + @Override + public void onReceive(Object message) throws Exception { + if ("create child".equals(message)) { + ActorRef child = getContext().actorOf(new Props(Child.class)); + sender().tell(child, self()); + } else if ("throw exception".equals(message)) { + this.receivedThrowException = true; + throw new RuntimeException(); + } else if ("check exception".equals(message)) { + sender().tell(receivedThrowException, self()); + } + } + } + + public static class Child extends RestcommUntypedActor { + + private boolean receivedThrowException; + + @SuppressWarnings("Duplicates") + @Override + public void onReceive(Object message) throws Exception { + if ("throw exception".equals(message)) { + this.receivedThrowException = true; + throw new RuntimeException(); + } else if ("check exception".equals(message)) { + sender().tell(receivedThrowException, self()); + } + } + } +} diff --git a/restcomm/restcomm.tts.acapela/src/main/java/org/restcomm/connect/tts/acapela/AcapelaSpeechSynthesizer.java b/restcomm/restcomm.tts.acapela/src/main/java/org/restcomm/connect/tts/acapela/AcapelaSpeechSynthesizer.java index 0bd6b2c374..398229d9ef 100644 --- a/restcomm/restcomm.tts.acapela/src/main/java/org/restcomm/connect/tts/acapela/AcapelaSpeechSynthesizer.java +++ b/restcomm/restcomm.tts.acapela/src/main/java/org/restcomm/connect/tts/acapela/AcapelaSpeechSynthesizer.java @@ -19,13 +19,9 @@ */ package org.restcomm.connect.tts.acapela; -import java.io.IOException; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import akka.actor.ActorRef; +import akka.event.Logging; +import akka.event.LoggingAdapter; import org.apache.commons.configuration.Configuration; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -37,22 +33,25 @@ import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.restcomm.connect.commons.cache.HashGenerator; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; +import org.restcomm.connect.commons.util.HttpUtils; import org.restcomm.connect.tts.api.GetSpeechSynthesizerInfo; import org.restcomm.connect.tts.api.SpeechSynthesizerException; import org.restcomm.connect.tts.api.SpeechSynthesizerInfo; import org.restcomm.connect.tts.api.SpeechSynthesizerRequest; import org.restcomm.connect.tts.api.SpeechSynthesizerResponse; -import org.restcomm.connect.commons.util.HttpUtils; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author quintana.thomas@gmail.com (Thomas Quintana) */ -public final class AcapelaSpeechSynthesizer extends UntypedActor { +public final class AcapelaSpeechSynthesizer extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); diff --git a/restcomm/restcomm.tts.att/src/main/java/org/restcomm/connect/tts/att/AttSpeechSynthesizer.java b/restcomm/restcomm.tts.att/src/main/java/org/restcomm/connect/tts/att/AttSpeechSynthesizer.java index 2a914345ce..515bff6b69 100644 --- a/restcomm/restcomm.tts.att/src/main/java/org/restcomm/connect/tts/att/AttSpeechSynthesizer.java +++ b/restcomm/restcomm.tts.att/src/main/java/org/restcomm/connect/tts/att/AttSpeechSynthesizer.java @@ -20,33 +20,31 @@ package org.restcomm.connect.tts.att; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - +import akka.actor.ActorRef; +import akka.event.Logging; +import akka.event.LoggingAdapter; import naturalvoices.ClientPlayer; import naturalvoices.Player; - import org.apache.commons.configuration.Configuration; import org.restcomm.connect.commons.cache.HashGenerator; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.tts.api.GetSpeechSynthesizerInfo; import org.restcomm.connect.tts.api.SpeechSynthesizerException; import org.restcomm.connect.tts.api.SpeechSynthesizerInfo; import org.restcomm.connect.tts.api.SpeechSynthesizerRequest; import org.restcomm.connect.tts.api.SpeechSynthesizerResponse; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * @author gvagenas * */ -public final class AttSpeechSynthesizer extends UntypedActor { +public final class AttSpeechSynthesizer extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private final Map men; diff --git a/restcomm/restcomm.tts.awspolly/src/main/java/org/restcomm/connect/tts/awspolly/AWSPollySpeechSyntetizer.java b/restcomm/restcomm.tts.awspolly/src/main/java/org/restcomm/connect/tts/awspolly/AWSPollySpeechSyntetizer.java index b281e7a1df..278915fed3 100644 --- a/restcomm/restcomm.tts.awspolly/src/main/java/org/restcomm/connect/tts/awspolly/AWSPollySpeechSyntetizer.java +++ b/restcomm/restcomm.tts.awspolly/src/main/java/org/restcomm/connect/tts/awspolly/AWSPollySpeechSyntetizer.java @@ -20,7 +20,6 @@ package org.restcomm.connect.tts.awspolly; import akka.actor.ActorRef; -import akka.actor.UntypedActor; import akka.event.Logging; import akka.event.LoggingAdapter; import com.amazonaws.auth.AWSCredentials; @@ -32,15 +31,9 @@ import com.amazonaws.services.polly.model.SynthesizeSpeechRequest; import com.amazonaws.services.polly.model.SynthesizeSpeechResult; import com.amazonaws.services.polly.model.VoiceId; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.configuration.Configuration; import org.restcomm.connect.commons.cache.HashGenerator; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.PcmToWavConverterUtils; import org.restcomm.connect.tts.api.GetSpeechSynthesizerInfo; import org.restcomm.connect.tts.api.SpeechSynthesizerException; @@ -48,10 +41,18 @@ import org.restcomm.connect.tts.api.SpeechSynthesizerRequest; import org.restcomm.connect.tts.api.SpeechSynthesizerResponse; +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.HashMap; +import java.util.Map; + /** * @author ricardo.limonta@gmail.com (Ricardo Limonta) */ -public class AWSPollySpeechSyntetizer extends UntypedActor { +public class AWSPollySpeechSyntetizer extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); private final AmazonPollyClient pollyClient; diff --git a/restcomm/restcomm.tts.voicerss/src/main/java/org/restcomm/connect/tts/voicerss/VoiceRSSSpeechSynthesizer.java b/restcomm/restcomm.tts.voicerss/src/main/java/org/restcomm/connect/tts/voicerss/VoiceRSSSpeechSynthesizer.java index ed99312e4e..81bb199d9b 100644 --- a/restcomm/restcomm.tts.voicerss/src/main/java/org/restcomm/connect/tts/voicerss/VoiceRSSSpeechSynthesizer.java +++ b/restcomm/restcomm.tts.voicerss/src/main/java/org/restcomm/connect/tts/voicerss/VoiceRSSSpeechSynthesizer.java @@ -19,17 +19,9 @@ */ package org.restcomm.connect.tts.voicerss; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import akka.actor.ActorRef; +import akka.event.Logging; +import akka.event.LoggingAdapter; import org.apache.commons.configuration.Configuration; import org.apache.http.Header; import org.apache.http.HttpResponse; @@ -43,21 +35,28 @@ import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.restcomm.connect.commons.cache.HashGenerator; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.tts.api.GetSpeechSynthesizerInfo; import org.restcomm.connect.tts.api.SpeechSynthesizerException; import org.restcomm.connect.tts.api.SpeechSynthesizerInfo; import org.restcomm.connect.tts.api.SpeechSynthesizerRequest; import org.restcomm.connect.tts.api.SpeechSynthesizerResponse; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import akka.event.Logging; -import akka.event.LoggingAdapter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author gvagenas@gmail.com (George Vagenas) */ -public final class VoiceRSSSpeechSynthesizer extends UntypedActor { +public final class VoiceRSSSpeechSynthesizer extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); diff --git a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreter.java b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreter.java index ed4a074577..0eaf9dbf69 100644 --- a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreter.java +++ b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreter.java @@ -22,14 +22,12 @@ import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorContext; import akka.actor.UntypedActorFactory; import akka.event.Logging; import akka.event.LoggingAdapter; - import org.apache.commons.configuration.Configuration; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; @@ -38,6 +36,7 @@ import org.joda.time.DateTime; import org.restcomm.connect.commons.configuration.RestcommConfiguration; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -69,7 +68,6 @@ import org.restcomm.connect.telephony.api.CallInfo; import org.restcomm.connect.telephony.api.CallResponse; import org.restcomm.connect.telephony.api.CallStateChanged; - import org.restcomm.connect.telephony.api.GetCallInfo; import org.restcomm.connect.ussd.commons.UssdInfoRequest; import org.restcomm.connect.ussd.commons.UssdMessageType; @@ -77,7 +75,6 @@ import javax.servlet.sip.SipServletRequest; import javax.servlet.sip.SipServletResponse; - import java.io.IOException; import java.math.BigDecimal; import java.net.URI; @@ -92,19 +89,16 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.regex.Pattern; -import static org.restcomm.connect.interpreter.rcml.Verbs.ussdCollect; -import static org.restcomm.connect.interpreter.rcml.Verbs.ussdLanguage; -import static org.restcomm.connect.interpreter.rcml.Verbs.ussdMessage; +import static org.restcomm.connect.interpreter.rcml.Verbs.*; /** * @author gvagenas */ -public class UssdInterpreter extends UntypedActor { +public class UssdInterpreter extends RestcommUntypedActor { // Logger. private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - private final ActorSystem system; static final int ERROR_NOTIFICATION = 0; static final int WARNING_NOTIFICATION = 1; static final Pattern PATTERN = Pattern.compile("[\\*#0-9]{1,12}"); @@ -174,13 +168,9 @@ public class UssdInterpreter extends UntypedActor { private final State ready; private final State notFound; - public UssdInterpreter(final Configuration configuration, final Sid account, final Sid phone, final String version, - final URI url, final String method, final URI fallbackUrl, final String fallbackMethod, final URI statusCallback, - final String statusCallbackMethod, final String emailAddress, final ActorRef callManager, - final ActorRef conferenceManager, final ActorRef sms, final DaoManager storage) { + public UssdInterpreter(final UssdInterpreterParams params) { super(); final ActorRef source = self(); - this.system = context().system(); uninitialized = new State("uninitialized", null, null); observeCall = new State("observe call", new ObserveCall(source), null); @@ -221,19 +211,19 @@ public UssdInterpreter(final Configuration configuration, final Sid account, fin // Initialize the FSM. this.fsm = new FiniteStateMachine(uninitialized, transitions); // Initialize the runtime stuff. - this.accountId = account; - this.phoneId = phone; - this.version = version; - this.url = url; - this.method = method; - this.fallbackUrl = fallbackUrl; - this.fallbackMethod = fallbackMethod; - this.statusCallback = statusCallback; - this.statusCallbackMethod = statusCallbackMethod; - this.emailAddress = emailAddress; - this.configuration = configuration; - - this.storage = storage; + this.accountId = params.getAccount(); + this.phoneId = params.getPhone(); + this.version = params.getVersion(); + this.url = params.getUrl(); + this.method = params.getMethod(); + this.fallbackUrl = params.getFallbackUrl(); + this.fallbackMethod = params.getFallbackMethod(); + this.statusCallback = params.getStatusCallback(); + this.statusCallbackMethod = params.getStatusCallbackMethod(); + this.emailAddress = params.getEmailAddress(); + this.configuration = params.getConfiguration(); + + this.storage = params.getStorage(); final Configuration runtime = configuration.subset("runtime-settings"); String path = runtime.getString("cache-path"); if (!path.endsWith("/")) { @@ -243,6 +233,15 @@ public UssdInterpreter(final Configuration configuration, final Sid account, fin this.downloader = downloader(); } + public static Props props(final UssdInterpreterParams params) { + return new Props(new UntypedActorFactory() { + @Override + public Actor create() throws Exception { + return new UssdInterpreter(params); + } + }); + } + private Notification notification(final int log, final int error, final String message) { final Notification.Builder builder = Notification.builder(); final Sid sid = Sid.generate(Sid.Type.NOTIFICATION); @@ -300,7 +299,7 @@ public Actor create() throws Exception { return new EmailService(configuration); } }); - return system.actorOf(props); + return getContext().actorOf(props); } ActorRef downloader() { @@ -311,7 +310,7 @@ public UntypedActor create() throws Exception { return new Downloader(); } }); - return system.actorOf(props); + return getContext().actorOf(props); } ActorRef parser(final String xml) { @@ -323,7 +322,7 @@ public UntypedActor create() throws Exception { return new Parser(xml, self()); } }); - return system.actorOf(props); + return getContext().actorOf(props); } void invalidVerb(final Tag verb) { diff --git a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreterBuilder.java b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreterBuilder.java deleted file mode 100644 index 31290f9daf..0000000000 --- a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreterBuilder.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * TeleStax, Open Source Cloud Communications - * Copyright 2011-2014, Telestax Inc and individual contributors - * by the @authors tag. - * - * This program is free software: you can redistribute it and/or modify - * under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation; either version 3 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * - */ - -package org.restcomm.connect.ussd.interpreter; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorFactory; -import org.apache.commons.configuration.Configuration; -import org.apache.log4j.Logger; -import org.restcomm.connect.commons.dao.Sid; -import org.restcomm.connect.dao.DaoManager; - -import java.net.URI; - -/** - * @author gvagenas - */ -public class UssdInterpreterBuilder { - - private static Logger logger = Logger.getLogger(UssdInterpreterBuilder.class); - private final ActorSystem system; - private Configuration configuration; - private DaoManager storage; - private ActorRef calls; - private ActorRef conferences; - private ActorRef sms; - private Sid account; - private Sid phone; - private String version; - private URI url; - private String method; - private URI fallbackUrl; - private String fallbackMethod; - private URI statusCallback; - private String statusCallbackMethod; - private String emailAddress; - - public UssdInterpreterBuilder(ActorSystem system) { - this.system = system; - } - - public ActorRef build() { - final Props props = new Props(new UntypedActorFactory() { - private static final long serialVersionUID = 1L; - @Override - public UntypedActor create() throws Exception { - return new UssdInterpreter(configuration, account, phone, version, url, method, fallbackUrl, fallbackMethod, - statusCallback, statusCallbackMethod, emailAddress, calls, conferences, sms, storage); - } - }); - return system.actorOf(props); - } - - public void setConfiguration(final Configuration configuration) { - this.configuration = configuration; - } - - public void setStorage(final DaoManager storage) { - this.storage = storage; - } - - public void setCallManager(final ActorRef calls) { - this.calls = calls; - } - - public void setAccount(final Sid account) { - this.account = account; - } - - public void setPhone(final Sid phone) { - this.phone = phone; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public void setMethod(final String method) { - this.method = method; - } - - public void setFallbackUrl(final URI fallbackUrl) { - this.fallbackUrl = fallbackUrl; - } - - public void setFallbackMethod(final String fallbackMethod) { - this.fallbackMethod = fallbackMethod; - } - - public void setStatusCallback(final URI statusCallback) { - this.statusCallback = statusCallback; - } - - public void setStatusCallbackMethod(final String statusCallbackMethod) { - this.statusCallbackMethod = statusCallbackMethod; - } - - public void setEmailAddress(final String emailAddress) { - this.emailAddress = emailAddress; - } - - public void setVersion(final String version) { - this.version = version; - } - -} diff --git a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreterParams.java b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreterParams.java new file mode 100644 index 0000000000..a35369542e --- /dev/null +++ b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/interpreter/UssdInterpreterParams.java @@ -0,0 +1,202 @@ +/* + * TeleStax, Open Source Cloud Communications + * Copyright 2011-2014, Telestax Inc and individual contributors + * by the @authors tag. + * + * This program is free software: you can redistribute it and/or modify + * under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * + */ + +package org.restcomm.connect.ussd.interpreter; + +import akka.actor.ActorRef; +import org.apache.commons.configuration.Configuration; +import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.dao.DaoManager; + +import java.net.URI; + +/** + * @author oleg.agafonov@telestax.com (Oleg Agafonov) + */ +public final class UssdInterpreterParams { + + private Configuration configuration; + private DaoManager storage; + private ActorRef sms; + private Sid account; + private Sid phone; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + private URI statusCallback; + private String statusCallbackMethod; + private String emailAddress; + + public Configuration getConfiguration() { + return configuration; + } + + public DaoManager getStorage() { + return storage; + } + + public ActorRef getSms() { + return sms; + } + + public Sid getAccount() { + return account; + } + + public Sid getPhone() { + return phone; + } + + public String getVersion() { + return version; + } + + public URI getUrl() { + return url; + } + + public String getMethod() { + return method; + } + + public URI getFallbackUrl() { + return fallbackUrl; + } + + public String getFallbackMethod() { + return fallbackMethod; + } + + public URI getStatusCallback() { + return statusCallback; + } + + public String getStatusCallbackMethod() { + return statusCallbackMethod; + } + + public String getEmailAddress() { + return emailAddress; + } + + private UssdInterpreterParams(Configuration configuration, DaoManager storage, ActorRef callManager, ActorRef sms, Sid account, Sid phone, String version, URI url, String method, URI fallbackUrl, String fallbackMethod, URI statusCallback, String statusCallbackMethod, String emailAddress) { + this.configuration = configuration; + this.storage = storage; + this.sms = sms; + this.account = account; + this.phone = phone; + this.version = version; + this.url = url; + this.method = method; + this.fallbackUrl = fallbackUrl; + this.fallbackMethod = fallbackMethod; + this.statusCallback = statusCallback; + this.statusCallbackMethod = statusCallbackMethod; + this.emailAddress = emailAddress; + } + + public static final class Builder { + private Configuration configuration; + private DaoManager storage; + private ActorRef callManager; + private ActorRef sms; + private Sid account; + private Sid phone; + private String version; + private URI url; + private String method; + private URI fallbackUrl; + private String fallbackMethod; + private URI statusCallback; + private String statusCallbackMethod; + private String emailAddress; + + public Builder setConfiguration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + public Builder setStorage(DaoManager storage) { + this.storage = storage; + return this; + } + + public Builder setSms(ActorRef sms) { + this.sms = sms; + return this; + } + + public Builder setAccount(Sid account) { + this.account = account; + return this; + } + + public Builder setPhone(Sid phone) { + this.phone = phone; + return this; + } + + public Builder setVersion(String version) { + this.version = version; + return this; + } + + public Builder setUrl(URI url) { + this.url = url; + return this; + } + + public Builder setMethod(String method) { + this.method = method; + return this; + } + + public Builder setFallbackUrl(URI fallbackUrl) { + this.fallbackUrl = fallbackUrl; + return this; + } + + public Builder setFallbackMethod(String fallbackMethod) { + this.fallbackMethod = fallbackMethod; + return this; + } + + public Builder setStatusCallback(URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public Builder setStatusCallbackMethod(String statusCallbackMethod) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public Builder setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + return this; + } + + public UssdInterpreterParams build() { + return new UssdInterpreterParams(configuration, storage, callManager, sms, account, phone, version, url, method, fallbackUrl, fallbackMethod, statusCallback, statusCallbackMethod, emailAddress); + } + } +} diff --git a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCall.java b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCall.java index c6a5db6460..c57e0d5fee 100644 --- a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCall.java +++ b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCall.java @@ -19,37 +19,14 @@ */ package org.restcomm.connect.ussd.telephony; -import java.math.BigDecimal; -import java.net.InetAddress; -import java.net.URI; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Currency; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.concurrent.TimeUnit; - -import javax.servlet.sip.Address; -import javax.servlet.sip.ServletParseException; -import javax.servlet.sip.SipApplicationSession; -import javax.servlet.sip.SipFactory; -import javax.servlet.sip.SipServletMessage; -import javax.servlet.sip.SipServletRequest; -import javax.servlet.sip.SipServletResponse; -import javax.servlet.sip.SipSession; -import javax.servlet.sip.SipURI; - +import akka.actor.ActorRef; +import akka.actor.UntypedActorContext; +import akka.event.Logging; +import akka.event.LoggingAdapter; import org.joda.time.DateTime; import org.restcomm.connect.commons.configuration.RestcommConfiguration; -import org.restcomm.connect.dao.CallDetailRecordsDao; -import org.restcomm.connect.dao.entities.CallDetailRecord; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.fsm.Action; import org.restcomm.connect.commons.fsm.FiniteStateMachine; import org.restcomm.connect.commons.fsm.State; @@ -58,29 +35,49 @@ import org.restcomm.connect.commons.patterns.Observing; import org.restcomm.connect.commons.patterns.StopObserving; import org.restcomm.connect.commons.telephony.CreateCallType; +import org.restcomm.connect.dao.CallDetailRecordsDao; +import org.restcomm.connect.dao.entities.CallDetailRecord; import org.restcomm.connect.telephony.api.Answer; import org.restcomm.connect.telephony.api.CallInfo; import org.restcomm.connect.telephony.api.CallResponse; import org.restcomm.connect.telephony.api.CallStateChanged; - import org.restcomm.connect.telephony.api.GetCallInfo; import org.restcomm.connect.telephony.api.GetCallObservers; import org.restcomm.connect.telephony.api.InitializeOutbound; import org.restcomm.connect.ussd.commons.UssdRestcommResponse; import org.restcomm.connect.ussd.interpreter.UssdInterpreter; - -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import akka.actor.UntypedActorContext; -import akka.event.Logging; -import akka.event.LoggingAdapter; import scala.concurrent.duration.Duration; +import javax.servlet.sip.Address; +import javax.servlet.sip.ServletParseException; +import javax.servlet.sip.SipApplicationSession; +import javax.servlet.sip.SipFactory; +import javax.servlet.sip.SipServletMessage; +import javax.servlet.sip.SipServletRequest; +import javax.servlet.sip.SipServletResponse; +import javax.servlet.sip.SipSession; +import javax.servlet.sip.SipURI; +import java.math.BigDecimal; +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Currency; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.concurrent.TimeUnit; + /** * @author gvagenas * */ -public class UssdCall extends UntypedActor { +public class UssdCall extends RestcommUntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); diff --git a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCallManager.java b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCallManager.java index 625ac02ebb..f4a8cd57d3 100644 --- a/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCallManager.java +++ b/restcomm/restcomm.ussd/src/main/java/org/restcomm/connect/ussd/telephony/UssdCallManager.java @@ -20,7 +20,6 @@ package org.restcomm.connect.ussd.telephony; import akka.actor.ActorRef; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; @@ -28,6 +27,7 @@ import akka.event.LoggingAdapter; import org.apache.commons.configuration.Configuration; import org.restcomm.connect.commons.dao.Sid; +import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.UriUtils; import org.restcomm.connect.dao.AccountsDao; import org.restcomm.connect.dao.ApplicationsDao; @@ -43,7 +43,7 @@ import org.restcomm.connect.telephony.api.InitializeOutbound; import org.restcomm.connect.telephony.api.util.CallControlHelper; import org.restcomm.connect.ussd.interpreter.UssdInterpreter; -import org.restcomm.connect.ussd.interpreter.UssdInterpreterBuilder; +import org.restcomm.connect.ussd.interpreter.UssdInterpreterParams; import javax.servlet.ServletContext; import javax.servlet.sip.ServletParseException; @@ -57,14 +57,12 @@ import java.util.regex.Pattern; import static javax.servlet.sip.SipServlet.OUTBOUND_INTERFACES; -import static javax.servlet.sip.SipServletResponse.SC_BAD_REQUEST; -import static javax.servlet.sip.SipServletResponse.SC_NOT_FOUND; -import static javax.servlet.sip.SipServletResponse.SC_OK; +import static javax.servlet.sip.SipServletResponse.*; /** * @author gvagenas */ -public class UssdCallManager extends UntypedActor { +public class UssdCallManager extends RestcommUntypedActor { static final int ERROR_NOTIFICATION = 0; static final int WARNING_NOTIFICATION = 1; @@ -85,8 +83,6 @@ public class UssdCallManager extends UntypedActor { private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); - private final ActorSystem system; - /** * @param configuration * @param context @@ -95,10 +91,8 @@ public class UssdCallManager extends UntypedActor { * @param factory * @param storage */ - public UssdCallManager(final ActorSystem system, Configuration configuration, ServletContext context, - ActorRef conferences, ActorRef sms, SipFactory factory, DaoManager storage) { + public UssdCallManager(Configuration configuration, ServletContext context, SipFactory factory, DaoManager storage) { super(); - this.system = system; this.configuration = configuration; this.context = context; this.sipFactory = factory; @@ -113,12 +107,13 @@ public UssdCallManager(final ActorSystem system, Configuration configuration, Se private ActorRef ussdCall() { final Props props = new Props(new UntypedActorFactory() { private static final long serialVersionUID = 1L; + @Override public UntypedActor create() throws Exception { return new UssdCall(sipFactory); } }); - return system.actorOf(props); + return getContext().actorOf(props); } private void check(final Object message) throws IOException { @@ -148,9 +143,9 @@ public void onReceive(final Object message) throws Exception { processRequest(request); } else if ("ACK".equalsIgnoreCase(method)) { processRequest(request); - } else if("BYE".equalsIgnoreCase(method)) { + } else if ("BYE".equalsIgnoreCase(method)) { processRequest(request); - } else if("CANCEL".equalsIgnoreCase(method)) { + } else if ("CANCEL".equalsIgnoreCase(method)) { processRequest(request); } } else if (message instanceof SipServletResponse) { @@ -181,7 +176,7 @@ private void invite(final Object message) throws Exception { final AccountsDao accounts = storage.getAccountsDao(); final ApplicationsDao applications = storage.getApplicationsDao(); final String toUser = CallControlHelper.getUserSipId(request, useTo); - if (redirectToHostedVoiceApp(self, request, accounts, applications, toUser)){ + if (redirectToHostedVoiceApp(self, request, accounts, applications, toUser)) { return; } @@ -202,7 +197,7 @@ private void invite(final Object message) throws Exception { * @throws Exception */ private boolean redirectToHostedVoiceApp(final ActorRef self, final SipServletRequest request, final AccountsDao accounts, - final ApplicationsDao applications, String id) throws Exception { + final ApplicationsDao applications, String id) throws Exception { boolean isFoundHostedApp = false; final IncomingPhoneNumbersDao numbersDao = storage.getIncomingPhoneNumbersDao(); @@ -212,10 +207,9 @@ private boolean redirectToHostedVoiceApp(final ActorRef self, final SipServletRe // This is a USSD Invite number = numbersDao.getIncomingPhoneNumber(id); if (number != null) { - final UssdInterpreterBuilder builder = new UssdInterpreterBuilder(system); + final UssdInterpreterParams.Builder builder = new UssdInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); - builder.setCallManager(self); builder.setAccount(number.getAccountSid()); builder.setVersion(number.getApiVersion()); final Account account = accounts.getAccount(number.getAccountSid()); @@ -238,14 +232,15 @@ private boolean redirectToHostedVoiceApp(final ActorRef self, final SipServletRe builder.setFallbackMethod(number.getUssdFallbackMethod()); builder.setStatusCallback(number.getStatusCallback()); builder.setStatusCallbackMethod(number.getStatusCallbackMethod()); - final ActorRef ussdInterpreter = builder.build(); + final Props props = UssdInterpreter.props(builder.build()); + final ActorRef ussdInterpreter = getContext().actorOf(props); final ActorRef ussdCall = ussdCall(); ussdCall.tell(request, self); ussdInterpreter.tell(new StartInterpreter(ussdCall), self); SipApplicationSession applicationSession = request.getApplicationSession(); - applicationSession.setAttribute("UssdCall","true"); + applicationSession.setAttribute("UssdCall", "true"); applicationSession.setAttribute(UssdInterpreter.class.getName(), ussdInterpreter); applicationSession.setAttribute(UssdCall.class.getName(), ussdCall); isFoundHostedApp = true; @@ -259,8 +254,8 @@ private boolean redirectToHostedVoiceApp(final ActorRef self, final SipServletRe private void processRequest(SipServletRequest request) throws IOException { final ActorRef ussdInterpreter = (ActorRef) request.getApplicationSession().getAttribute(UssdInterpreter.class.getName()); - if(ussdInterpreter != null) { - logger.info("Dispatching Request: "+request.getMethod()+" to UssdInterpreter: "+ussdInterpreter); + if (ussdInterpreter != null) { + logger.info("Dispatching Request: " + request.getMethod() + " to UssdInterpreter: " + ussdInterpreter); ussdInterpreter.tell(request, self()); } else { final SipServletResponse notFound = request.createResponse(SipServletResponse.SC_NOT_FOUND); @@ -275,8 +270,8 @@ private ActorRef outbound(final Object message) throws ServletParseException { final String ussdUsername = (request.username() != null) ? request.username() : ussdGatewayUsername; final String ussdPassword = (request.password() != null) ? request.password() : ussdGatewayPassword; - SipURI from = (SipURI)sipFactory.createSipURI(request.from(), uri); - SipURI to = (SipURI)sipFactory.createSipURI(request.to(), uri); + SipURI from = (SipURI) sipFactory.createSipURI(request.from(), uri); + SipURI to = (SipURI) sipFactory.createSipURI(request.to(), uri); String transport = (to.getTransportParam() != null) ? to.getTransportParam() : "udp"; //from = outboundInterface(transport); @@ -293,8 +288,7 @@ private ActorRef outbound(final Object message) throws ServletParseException { private SipURI outboundInterface(String transport) { SipURI result = null; - @SuppressWarnings("unchecked") - final List uris = (List) context.getAttribute(OUTBOUND_INTERFACES); + @SuppressWarnings("unchecked") final List uris = (List) context.getAttribute(OUTBOUND_INTERFACES); for (final SipURI uri : uris) { final String interfaceTransport = uri.getTransportParam(); if (transport.equalsIgnoreCase(interfaceTransport)) { @@ -307,17 +301,17 @@ private SipURI outboundInterface(String transport) { private void execute(final Object message) { final ExecuteCallScript request = (ExecuteCallScript) message; final ActorRef self = self(); - final UssdInterpreterBuilder builder = new UssdInterpreterBuilder(system); + final UssdInterpreterParams.Builder builder = new UssdInterpreterParams.Builder(); builder.setConfiguration(configuration); builder.setStorage(storage); - builder.setCallManager(self); builder.setAccount(request.account()); builder.setVersion(request.version()); builder.setUrl(request.url()); builder.setMethod(request.method()); builder.setFallbackUrl(request.fallbackUrl()); builder.setFallbackMethod(request.fallbackMethod()); - final ActorRef interpreter = builder.build(); + final Props props = UssdInterpreter.props(builder.build()); + final ActorRef interpreter = getContext().actorOf(props); interpreter.tell(new StartInterpreter(request.call()), self); }