24
24
import java .io .Serializable ;
25
25
import java .io .IOException ;
26
26
import java .io .ObjectInputStream ;
27
+ import java .util .Objects ;
27
28
29
+ import javax .naming .NamingException ;
30
+ import javax .naming .RefAddr ;
31
+ import javax .naming .Reference ;
32
+ import javax .naming .Referenceable ;
33
+ import javax .naming .StringRefAddr ;
28
34
29
35
/**
30
36
* Manages a pool of AS400 objects. A connection pool is used to
84
90
* <li>PropertyChangeEvent</li>
85
91
* </ul>
86
92
**/
87
- public class AS400ConnectionPool extends ConnectionPool implements Serializable
93
+ public class AS400ConnectionPool extends ConnectionPool implements Serializable , Referenceable
88
94
{
89
95
static final long serialVersionUID = 4L ;
96
+
97
+ private static final String CCSID_PROPERTY = "ccsid" ;
98
+ private static final String CLEANUP_INTERVAL_PROPERTY = "cleanupInterval" ;
99
+ private static final String MAX_CONNECTIONS_PROPERTY = "maxConnections" ;
100
+ private static final String MAX_INACTIVITY_PROPERTY = "maxInactivity" ;
101
+ private static final String MAX_LIFETIME_PROPERTY = "maxLifetime" ;
102
+ private static final String MAX_USE_COUNT_PROPERTY = "maxUseCount" ;
103
+ private static final String MAX_USE_TIME_PROPERTY = "maxUseTime" ;
104
+ private static final String PRETEST_CONNECTIONS_PROPERTY = "pretestConnections" ;
105
+ private static final String RUN_MAINTENANCE_PROPERTY = "runMaintenance" ;
106
+ private static final String THREAD_USED_PROPERTY = "threadUsed" ;
90
107
91
108
/**
92
109
Indicates that the CCSID used for new connections is the same as the system default CCSID.
@@ -109,13 +126,105 @@ public AS400ConnectionPool()
109
126
initializeTransient ();
110
127
}
111
128
129
+ /**
130
+ * Constructs an AS400ConnectionPool from the specified Reference object.
131
+ *
132
+ * @param reference to retrieve the ConnectionPool properties from
133
+ */
134
+ AS400ConnectionPool (Reference reference ) {
135
+ super ();
136
+ initializeTransient ();
137
+
138
+ Objects .requireNonNull (reference , "reference" );
139
+ Enumeration <RefAddr > list = reference .getAll ();
140
+ while (list .hasMoreElements ()) {
141
+ RefAddr refAddr = list .nextElement ();
142
+ String property = refAddr .getType ();
143
+ String value = (String ) refAddr .getContent ();
144
+ switch (property ) {
145
+ case CCSID_PROPERTY :
146
+ setCCSID (Integer .parseInt (value ));
147
+ break ;
148
+ case CLEANUP_INTERVAL_PROPERTY :
149
+ setCleanupInterval (Long .parseLong (value ));
150
+ break ;
151
+ case MAX_CONNECTIONS_PROPERTY :
152
+ setMaxConnections (Integer .parseInt (value ));
153
+ break ;
154
+ case MAX_INACTIVITY_PROPERTY :
155
+ setMaxInactivity (Long .parseLong (value ));
156
+ break ;
157
+ case MAX_LIFETIME_PROPERTY :
158
+ setMaxLifetime (Long .parseLong (value ));
159
+ break ;
160
+ case MAX_USE_COUNT_PROPERTY :
161
+ setMaxUseCount (Integer .parseInt (value ));
162
+ break ;
163
+ case MAX_USE_TIME_PROPERTY :
164
+ setMaxUseTime (Long .parseLong (value ));
165
+ break ;
166
+ case PRETEST_CONNECTIONS_PROPERTY :
167
+ setPretestConnections (Boolean .parseBoolean (value ));
168
+ break ;
169
+ case RUN_MAINTENANCE_PROPERTY :
170
+ setRunMaintenance (Boolean .parseBoolean (value ));
171
+ break ;
172
+ case THREAD_USED_PROPERTY :
173
+ setThreadUsed (Boolean .parseBoolean (value ));
174
+ break ;
175
+ default :
176
+ if (SocketProperties .isSocketProperty (property )) {
177
+ socketProperties_ .restore (property , value );
178
+ }
179
+ break ;
180
+ }
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Returns the Reference object for the pool object. This is used by
186
+ * JNDI when bound in a JNDI naming service. Contains the information
187
+ * necessary to reconstruct the pool object when it is later
188
+ * retrieved from JNDI via an object factory.
189
+ *
190
+ * @return A Reference object of the pool object.
191
+ * @exception NamingException If a naming error occurs in resolving the
192
+ * object.
193
+ *
194
+ */
195
+ @ Override
196
+ public Reference getReference () throws NamingException {
197
+ Trace .log (Trace .INFORMATION , "AS400ConnectionPool.getReference" );
198
+
199
+ Reference ref = new Reference (this .getClass ().getName (),
200
+ AS400ObjectFactory .class .getName (),
201
+ null );
202
+
203
+ ref .add (new StringRefAddr (CCSID_PROPERTY , Integer .toString (getCCSID ())));
204
+ ref .add (new StringRefAddr (CLEANUP_INTERVAL_PROPERTY , Long .toString (getCleanupInterval ())));
205
+ ref .add (new StringRefAddr (MAX_CONNECTIONS_PROPERTY , Integer .toString (getMaxConnections ())));
206
+ ref .add (new StringRefAddr (MAX_INACTIVITY_PROPERTY , Long .toString (getMaxInactivity ())));
207
+ ref .add (new StringRefAddr (MAX_LIFETIME_PROPERTY , Long .toString (getMaxLifetime ())));
208
+ ref .add (new StringRefAddr (MAX_USE_COUNT_PROPERTY , Integer .toString (getMaxUseCount ())));
209
+ ref .add (new StringRefAddr (MAX_USE_TIME_PROPERTY , Long .toString (getMaxUseTime ())));
210
+ ref .add (new StringRefAddr (PRETEST_CONNECTIONS_PROPERTY , Boolean .toString (isPretestConnections ())));
211
+ ref .add (new StringRefAddr (RUN_MAINTENANCE_PROPERTY , Boolean .toString (isRunMaintenance ())));
212
+ ref .add (new StringRefAddr (THREAD_USED_PROPERTY , Boolean .toString (isThreadUsed ())));
213
+
214
+ // Add the Socket options
215
+ socketProperties_ .save (ref );
216
+
217
+ return ref ;
218
+ }
219
+
112
220
/**
113
221
* Remove any connections that have exceeded maximum inactivity time, replace any
114
222
* that have aged past maximum usage or maximum lifetime, and remove any that have
115
223
* been in use too long.
116
224
*
117
225
* @see ConnectionPoolProperties
118
226
**/
227
+ @ Override
119
228
void cleanupConnections ()
120
229
{
121
230
synchronized (as400ConnectionPool_ )
@@ -148,6 +257,7 @@ void cleanupConnections()
148
257
/**
149
258
* Close and cleanup the connection pool.
150
259
**/
260
+ @ Override
151
261
public void close ()
152
262
{
153
263
log (ResourceBundleLoader .getText ("AS400CP_SHUTDOWN" ));
0 commit comments