Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
273 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...r/operations/service/akka/actors/core/endpoint/AbstractEndpointActorMessageProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint; | ||
|
||
import org.kaaproject.kaa.common.hash.EndpointObjectHash; | ||
import org.kaaproject.kaa.server.operations.service.OperationsService; | ||
import org.kaaproject.kaa.server.operations.service.akka.messages.core.endpoint.EndpointStopMessage; | ||
import org.kaaproject.kaa.server.operations.service.akka.messages.core.session.ActorTimeoutMessage; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import akka.actor.ActorContext; | ||
import akka.actor.ActorRef; | ||
|
||
public abstract class AbstractEndpointActorMessageProcessor<T extends AbstractEndpointActorState> { | ||
|
||
/** The Constant LOG. */ | ||
private static final Logger LOG = LoggerFactory.getLogger(AbstractEndpointActorMessageProcessor.class); | ||
|
||
protected final T state; | ||
|
||
/** The operations service. */ | ||
protected final OperationsService operationsService; | ||
|
||
/** The app token. */ | ||
protected final String appToken; | ||
|
||
/** The key. */ | ||
protected final EndpointObjectHash key; | ||
|
||
/** The actor key. */ | ||
protected final String actorKey; | ||
|
||
/** The endpoint key. */ | ||
protected final String endpointKey; | ||
|
||
private final long inactivityTimeout; | ||
|
||
public AbstractEndpointActorMessageProcessor(T state, OperationsService operationsService, String appToken, EndpointObjectHash key, | ||
String actorKey, String endpointKey, long inactivityTimeout) { | ||
super(); | ||
this.state = state; | ||
this.operationsService = operationsService; | ||
this.inactivityTimeout = inactivityTimeout; | ||
this.appToken = appToken; | ||
this.key = key; | ||
this.actorKey = actorKey; | ||
this.endpointKey = endpointKey; | ||
} | ||
|
||
public long getInactivityTimeout() { | ||
return inactivityTimeout; | ||
} | ||
|
||
public void processActorTimeoutMessage(ActorContext context, ActorTimeoutMessage message) { | ||
if (state.getLastActivityTime() <= message.getLastActivityTime()) { | ||
LOG.debug("[{}][{}] Request stop of endpoint actor due to inactivity timeout", endpointKey, actorKey); | ||
tellParent(context, new EndpointStopMessage(key, actorKey, context.self())); | ||
} | ||
} | ||
|
||
protected void tellParent(ActorContext context, Object response) { | ||
context.parent().tell(response, context.self()); | ||
} | ||
|
||
protected void tellActor(ActorContext context, ActorRef target, Object message) { | ||
target.tell(message, context.self()); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...t/kaa/server/operations/service/akka/actors/core/endpoint/AbstractEndpointActorState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint; | ||
|
||
public abstract class AbstractEndpointActorState { | ||
|
||
protected final String endpointKey; | ||
protected final String actorKey; | ||
private long lastActivityTime; | ||
|
||
public AbstractEndpointActorState(String endpointKey, String actorKey) { | ||
super(); | ||
this.endpointKey = endpointKey; | ||
this.actorKey = actorKey; | ||
} | ||
|
||
public long getLastActivityTime() { | ||
return lastActivityTime; | ||
} | ||
|
||
public void setLastActivityTime(long time) { | ||
this.lastActivityTime = time; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...project/kaa/server/operations/service/akka/actors/core/endpoint/EndpointActorCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint; | ||
|
||
import java.util.UUID; | ||
|
||
import org.kaaproject.kaa.common.hash.EndpointObjectHash; | ||
import org.kaaproject.kaa.server.operations.service.akka.AkkaContext; | ||
|
||
import akka.japi.Creator; | ||
|
||
/** | ||
* The Class ActorCreator. | ||
*/ | ||
public abstract class EndpointActorCreator<T> implements Creator<T> { | ||
|
||
/** The Constant serialVersionUID. */ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** The Akka service context */ | ||
protected final AkkaContext context; | ||
|
||
/** The actor key */ | ||
protected final String actorKey; | ||
|
||
/** The app token. */ | ||
protected final String appToken; | ||
|
||
/** The endpoint key. */ | ||
protected final EndpointObjectHash endpointKey; | ||
|
||
/** | ||
* Instantiates a new actor creator. | ||
* | ||
* @param context | ||
* the context | ||
* @param endpointActorKey | ||
* the endpoint actor key | ||
* @param appToken | ||
* the app token | ||
* @param endpointKey | ||
* the endpoint key | ||
*/ | ||
public EndpointActorCreator(AkkaContext context, String endpointActorKey, String appToken, EndpointObjectHash endpointKey) { | ||
super(); | ||
this.context = context; | ||
this.actorKey = endpointActorKey; | ||
this.appToken = appToken; | ||
this.endpointKey = endpointKey; | ||
} | ||
|
||
public static String generateActorKey(){ | ||
return UUID.randomUUID().toString().replaceAll("-", ""); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...t/kaa/server/operations/service/akka/actors/core/endpoint/global/GlobalEndpointActor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.global; | ||
|
||
import org.kaaproject.kaa.common.hash.EndpointObjectHash; | ||
import org.kaaproject.kaa.server.operations.service.akka.AkkaContext; | ||
|
||
public class GlobalEndpointActor { | ||
|
||
GlobalEndpointActor(AkkaContext context, String actorKey, String appToken, EndpointObjectHash endpointKey) { | ||
// TODO Auto-generated constructor stub | ||
} | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...erver/operations/service/akka/actors/core/endpoint/global/GlobalEndpointActorCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.global; | ||
|
||
import org.kaaproject.kaa.common.hash.EndpointObjectHash; | ||
import org.kaaproject.kaa.server.operations.service.akka.AkkaContext; | ||
import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.EndpointActorCreator; | ||
|
||
public class GlobalEndpointActorCreator extends EndpointActorCreator<GlobalEndpointActor> { | ||
|
||
private static final long serialVersionUID = 9080174513879065821L; | ||
|
||
public GlobalEndpointActorCreator(AkkaContext context, String endpointActorKey, String appToken, EndpointObjectHash key) { | ||
super(context, endpointActorKey, appToken, key); | ||
} | ||
|
||
@Override | ||
public GlobalEndpointActor create() throws Exception { | ||
return new GlobalEndpointActor(context, actorKey, appToken, endpointKey); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...rations/service/akka/actors/core/endpoint/global/GlobalEndpointActorMessageProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.global; | ||
|
||
import org.kaaproject.kaa.common.hash.EndpointObjectHash; | ||
import org.kaaproject.kaa.server.common.Base64Util; | ||
import org.kaaproject.kaa.server.operations.service.akka.AkkaContext; | ||
import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.AbstractEndpointActorMessageProcessor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class GlobalEndpointActorMessageProcessor extends AbstractEndpointActorMessageProcessor<GlobalEndpointActorState> { | ||
|
||
/** The Constant LOG. */ | ||
private static final Logger LOG = LoggerFactory.getLogger(GlobalEndpointActorMessageProcessor.class); | ||
|
||
public GlobalEndpointActorMessageProcessor(AkkaContext context, String appToken, EndpointObjectHash key, String actorKey) { | ||
super(new GlobalEndpointActorState(Base64Util.encode(key.getData()), actorKey), context.getOperationsService(), appToken, key, | ||
actorKey, Base64Util.encode(key.getData()), context.getGlobalEndpointTimeout()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../server/operations/service/akka/actors/core/endpoint/global/GlobalEndpointActorState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.global; | ||
|
||
import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.AbstractEndpointActorState; | ||
|
||
public class GlobalEndpointActorState extends AbstractEndpointActorState { | ||
|
||
public GlobalEndpointActorState(String endpointKey, String actorKey) { | ||
super(endpointKey, actorKey); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../server/operations/service/akka/actors/core/endpoint/local/LocalEndpointActorCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.local; | ||
|
||
import org.kaaproject.kaa.common.hash.EndpointObjectHash; | ||
import org.kaaproject.kaa.server.operations.service.akka.AkkaContext; | ||
import org.kaaproject.kaa.server.operations.service.akka.actors.core.endpoint.EndpointActorCreator; | ||
|
||
public class LocalEndpointActorCreator extends EndpointActorCreator<LocalEndpointActor> { | ||
|
||
private static final long serialVersionUID = 9080174513879065821L; | ||
|
||
public LocalEndpointActorCreator(AkkaContext context, String endpointActorKey, String appToken, EndpointObjectHash key) { | ||
super(context, endpointActorKey, appToken, key); | ||
} | ||
|
||
@Override | ||
public LocalEndpointActor create() throws Exception { | ||
return new LocalEndpointActor(context, actorKey, appToken, endpointKey); | ||
} | ||
|
||
} |
Oops, something went wrong.