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
|
/*******************************************************************************
* Copyright (c) 2013 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* CONTRIBUTORS:
* Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.runtime.java.modelbase;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
* This class serves as base class for generated classes.
* It specializes {@link OptionalActorInterfaceBase} for scalar optional actors.
*
* @see OptionalActorInterfaceBase
*
* @author Henrik Rentz-Reichert
*/
public class ScalarOptionalActorInterfaceBase extends OptionalActorInterfaceBase {
/**
* Our single actor instance or {@code null} if not instantiated or destroyed.
*/
private ActorClassBase actor = null;
/**
* The only constructor.
*
* @param parent the parent event receiver
* @param name the name of the actor reference
* @param clsname the actor class name of the reference
*/
protected ScalarOptionalActorInterfaceBase(IEventReceiver parent, String name, String clsname) {
super(parent, name, clsname);
}
/**
* This method instantiates and starts an optional actor (together with its contained instances).
*
* @param actorClass the name of the actor class to be instantiated
* @param thread the ID of the message service (and thus the thread) for the newly created instances
* @return {@code true} on success or {@code false} on failure
*/
public boolean createOptionalActor(String actorClass, int thread) {
return createOptionalActor(actorClass, thread, null);
}
/**
* This method instantiates and starts an optional actor (together with its contained instances).
*
* @param actorClass the name of the actor class to be instantiated
* @param thread the ID of the message service (and thus the thread) for the newly created instances
* @param input an optional {@link ObjectInput}
* @return {@code true} on success or {@code false} on failure
*/
public boolean createOptionalActor(String actorClass, int thread, ObjectInput input) {
if (actor!=null)
return false;
setSubtreeThread(thread);
// SubSystemClass.createOptionalActor() will set our PathTo* maps
IOptionalActorFactory factory = RTServices.getInstance().getSubSystem().getFactory(getClassName(), actorClass);
if (factory==null)
return false;
// the factory will set our path2peers map
logCreation(actorClass, getName());
actor = factory.create(this, getName());
startupSubTree(actor, input);
return actor!=null;
}
/**
* Destroys our actor instance.
* Before actual destruction the instances are shut down properly.
*
* @return {@code true} on success, {@code false} else
*/
public boolean destroyOptionalActor() {
return destroyOptionalActor(null);
}
/**
* Destroys our actor instance.
* Before actual destruction the instances are shut down properly.
*
* @param output an optional {@link ObjectOutput}
* @return {@code true} on success, {@code false} else
*/
public boolean destroyOptionalActor(ObjectOutput output) {
if (actor==null)
return false;
logDeletion(getName());
if (output!=null)
saveActor(actor, output);
actor.destroy();
actor = null;
return true;
}
public String toString(){
return "ScalarOptionalActorInterface(className="+getClassName()+", instancePath="+getInstancePath()+")";
}
}
|