|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ObjectDataBroker.java | 100% | 100% | 100% | 100% |
|
1 |
/*
|
|
2 |
|
|
3 |
VRMoo Common - Virtual Reality Object Oriented MUD Common Code
|
|
4 |
Copyright (C) 2003 VRMoo Development Team
|
|
5 |
|
|
6 |
|
|
7 |
This program is free software; you can redistribute it and/or modify
|
|
8 |
it under the terms of the GNU General Public License as published by
|
|
9 |
the Free Software Foundation; either version 2 of the License, or
|
|
10 |
(at your option) any later version.
|
|
11 |
|
|
12 |
This program is distributed in the hope that it will be useful,
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
GNU General Public License for more details.
|
|
16 |
|
|
17 |
You should have received a copy of the GNU General Public License
|
|
18 |
along with this program; if not, write to the Free Software
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
|
|
21 |
|
|
22 |
For information about VRMoo and its authors, please visit the website:
|
|
23 |
http://www.vrmoo.org/
|
|
24 |
|
|
25 |
*/
|
|
26 |
|
|
27 |
package org.vrmoo.common.objectbroker;
|
|
28 |
|
|
29 |
import org.vrmoo.common.data.BrokerableObject;
|
|
30 |
import org.vrmoo.common.data.ObjectData;
|
|
31 |
import org.vrmoo.common.exception.VRMooException;
|
|
32 |
import org.vrmoo.common.exception.VRMooParseException;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* This class is a singleton responsible for handling the complex tasks of
|
|
36 |
* managing <code>ObjectData</code> instances that are distributed between
|
|
37 |
* a world on the VRMoo Server and several VRMoo Clients.
|
|
38 |
* <P>
|
|
39 |
* This object broker relies on a client/server architecture. In a distributed
|
|
40 |
* environment, there will be an instance of this class on a server, as well as
|
|
41 |
* an instance of this class on several clients. This class relies on having the
|
|
42 |
* instance located on the server becoming the server instance. That one
|
|
43 |
* instance will coordinate all of the other instances.
|
|
44 |
* <P>
|
|
45 |
* To specify an instance of this class as a server instance, the VRMoo Server
|
|
46 |
* must call the static <code>setServerInstance()</code> method before using
|
|
47 |
* this class for any other purpose.
|
|
48 |
*
|
|
49 |
* @author Jeff Weston
|
|
50 |
*/
|
|
51 |
public class ObjectDataBroker extends AbstractObjectBroker |
|
52 |
{ |
|
53 |
/**
|
|
54 |
* The client instance of this class.
|
|
55 |
*/
|
|
56 |
private static ObjectDataBroker clientInstance = null; |
|
57 |
|
|
58 |
/**
|
|
59 |
* Construct a server instance of this class.
|
|
60 |
*/
|
|
61 | 3 |
public ObjectDataBroker( )
|
62 |
{ |
|
63 | 3 |
this( true ); |
64 |
} |
|
65 |
|
|
66 |
/**
|
|
67 |
* The client instance of this class is a singleton, so make the constructor
|
|
68 |
* that can create the client instance private. The client instance of this
|
|
69 |
* class can only be instantiated by the <code>getClientInstance()</code>
|
|
70 |
* method.
|
|
71 |
*
|
|
72 |
* @param isServerInstance tell this instance if it is a server instance
|
|
73 |
*/
|
|
74 | 4 |
private ObjectDataBroker( boolean isServerInstance ) |
75 |
{ |
|
76 | 4 |
super( isServerInstance );
|
77 |
} |
|
78 |
|
|
79 |
/**
|
|
80 |
* Static method for getting the client instance of this class.
|
|
81 |
*
|
|
82 |
* @return the client instance of <code>ObjectDataBroker</code>
|
|
83 |
*/
|
|
84 | 3 |
public static synchronized ObjectDataBroker getClientInstance( ) |
85 |
{ |
|
86 | 3 |
if ( clientInstance == null ) |
87 |
{ |
|
88 | 1 |
clientInstance = new ObjectDataBroker( false ); |
89 |
} |
|
90 | 3 |
return clientInstance;
|
91 |
} |
|
92 |
|
|
93 |
/**
|
|
94 |
* Gets an <code>ObjectData</code> with the specified name.
|
|
95 |
*
|
|
96 |
* @param name the name to search for.
|
|
97 |
*
|
|
98 |
* @return the mathing <code>ObjectData</code>
|
|
99 |
*
|
|
100 |
* @throws VRMooException if the name isn't found
|
|
101 |
*/
|
|
102 | 1 |
public ObjectData getObjectData( String name )
|
103 |
throws VRMooException
|
|
104 |
{ |
|
105 | 1 |
return ( ObjectData ) super.getBrokerableObject( name ); |
106 |
} |
|
107 |
|
|
108 |
/**
|
|
109 |
* Public interface for setting <code>ObjectData</code> objects.
|
|
110 |
*
|
|
111 |
* @param objectData the <code>ObjectData</code> to set
|
|
112 |
*/
|
|
113 | 3 |
public void setObjectData( ObjectData objectData ) |
114 |
{ |
|
115 | 3 |
setBrokerableObject( objectData, null );
|
116 |
} |
|
117 |
|
|
118 |
/**
|
|
119 |
* Remove the <code>ObjectData</code> with the specified name.
|
|
120 |
*
|
|
121 |
* @param name the name of the <code>ObjectData</code> to remove
|
|
122 |
*/
|
|
123 | 1 |
public void removeObjectData( String name ) |
124 |
{ |
|
125 | 1 |
super.removeBrokerableObject( name, null ); |
126 |
} |
|
127 |
|
|
128 |
/**
|
|
129 |
* Get the name of all of the <code>ObjectData</code> objects available
|
|
130 |
* from this class.
|
|
131 |
*
|
|
132 |
* @return the array of <code>ObjectData</code> names
|
|
133 |
*/
|
|
134 | 1 |
public String[ ] getObjectDataNames( )
|
135 |
{ |
|
136 | 1 |
return super.getBrokerableObjectNames( ); |
137 |
} |
|
138 |
|
|
139 |
/**
|
|
140 |
* Get the prefix used by this broker sub-class when sending or receiving
|
|
141 |
* commands.
|
|
142 |
*
|
|
143 |
* @return the prefix used for sending and receiving commands
|
|
144 |
*/
|
|
145 | 8 |
protected String getBrokerPrefix( )
|
146 |
{ |
|
147 | 8 |
return "objectDataBroker:"; |
148 |
} |
|
149 |
|
|
150 |
/**
|
|
151 |
* Get an instance of a brokerable object by parsing a string of encoded
|
|
152 |
* data representing the object.
|
|
153 |
*
|
|
154 |
* @param data the encoded data for the object
|
|
155 |
*
|
|
156 |
* @return the parsed <code>BrokerableObject</code>
|
|
157 |
*
|
|
158 |
* @throws VRMooParseException for any parsing errors that occur
|
|
159 |
*/
|
|
160 | 1 |
protected BrokerableObject parseBrokerableObject( String data )
|
161 |
throws VRMooParseException
|
|
162 |
{ |
|
163 | 1 |
return new ObjectData( data ); |
164 |
} |
|
165 |
} |
|
166 |
|
|