/
IRuntime.java
138 lines (121 loc) · 5.48 KB
/
IRuntime.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Copyright (C) 2015 Electronic Arts Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.ea.orbit.actors.runtime;
import com.ea.orbit.actors.IAddressable;
import com.ea.orbit.actors.IRemindable;
import com.ea.orbit.actors.cluster.INodeAddress;
import com.ea.orbit.concurrent.Task;
import java.lang.reflect.Method;
import java.time.Clock;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
/**
* Interface used by the generated code to interact with the orbit actors runtime.
*/
public interface IRuntime
{
/**
* Sends a message to an actor or observer.
*
* @param toReference destination actor reference or observer reference
* @param oneWay should expect an answer,
* if false the task is completed with null.
* @param methodId the generated id for the method
* @param params the method parameters, must all be serializable.
* @return a future with the return value, or a future with null (if one-way)
*/
Task<?> sendMessage(IAddressable toReference, boolean oneWay, int methodId, Object[] params);
/**
* Handles calls to actor reference methods.
*
* @param toReference destination actor reference or observer reference
* @param oneWay should expect an answer,
* if false the task is completed with null.
* @param methodId the generated id for the method
* @param params the method parameters, must all be serializable.
* @return a future with the return value, or a future with null (if one-way)
*/
Task<?> invoke(IAddressable toReference, Method m, boolean oneWay, final int methodId, final Object[] params);
/**
* Registers a timer to for the orbit actor
*
* @param actor the actor requesting the timer.
* @param taskCallable a callable that must return a task.
* @param dueTime the first time the timer will tick.
* @param period the period of subsequent ticks (if ZERO then will only tick once)
* @param timeUnit the time unit for period and dueTime
* @return a registration that allows to cancel the timer.
*/
Registration registerTimer(OrbitActor<?> actor, Callable<Task<?>> taskCallable, long dueTime, long period, TimeUnit timeUnit);
/**
* Gets the local clock. It's usually the system clock, but it can be changed for testing.
*
* @return the clock that should be used for checking the time during tests.
*/
Clock clock();
/**
* Registers or updated a persisted reminder.
*
* @param actor the reference to the actor.
* @param reminderName the remainder's name
* @param dueTime how long since now the first tick should be triggered.
* @param period after the first tick, how often should the reminder be called.
* @param timeUnit the time unit for dueTime and period
* @return completion promise for this operation
*/
Task<?> registerReminder(IRemindable actor, String reminderName, long dueTime, long period, TimeUnit timeUnit);
/**
* Removes a previously registered reminder.
*
* @param actor the actor that registered this reminder
* @param reminderName the remainder's name
* @return completion promise for this operation
*/
Task<?> unregisterReminder(IRemindable actor, String reminderName);
/**
* Gets a string that represents uniquely the node that currently holds this actor.
*
* @return unique identity string
*/
String runtimeIdentity();
/**
* Gets current Activation, the actor reference that is currently invoking the method
*
* @return caller actor
*/
ActorReference getCurrentActivation();
/**
* Gets a long representing the current tracing id
*
* @return unique trace id
*/
long getCurrentTraceId();
/**
* Gets an address for an active actor
*
* @return actor address, null if actor is not active
*/
Task<INodeAddress> locateActiveActor(final IAddressable actorReference);
}