Changeset 15085
- Timestamp:
- 03/09/10 17:30:59 (2 years ago)
- Location:
- trunk/Jav_Transform/src/com/scenari/s/co/transform/oo
- Files:
-
- 3 edited
-
IOoConnection.java (modified) (1 diff)
-
OoConnectionPoolLoader.java (modified) (3 diffs)
-
impl/OoConnection.java (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Jav_Transform/src/com/scenari/s/co/transform/oo/IOoConnection.java
r14602 r15085 44 44 */ 45 45 public interface IOoConnection { 46 46 47 47 public void setAutoLaunch(boolean pAutoLaunch); 48 48 49 public void setAutoKill(boolean pAutoKill); 50 49 51 public void setHost(String pHost); 50 52 51 53 public void setPort(int pPort); 52 54 53 55 public void setMaxCnxAttempts(int pMaxAttempts); 54 56 55 57 public void setPipeMode(boolean pPipeMode); 56 58 57 59 public void setPipeName(String pPipeName); 58 60 59 61 public void setProfilePath(String pProfilePath); 60 62 61 63 public void setHeadless(boolean pHeadless); 62 64 63 65 public void setReCheckInterval(long pMs); 64 66 65 67 } -
trunk/Jav_Transform/src/com/scenari/s/co/transform/oo/OoConnectionPoolLoader.java
r15083 r15085 58 58 * [!-- Pour un server local, lancé automatiquement, en accès socket TCP/IP. --] 59 59 * [ooConnection host="localhost" port="8100" autoLaunch="true"/] 60 * 61 * [!-- Pour un server local, lancé automatiquement, en accès socket TCP/IP et kill automatique 62 * à la fermeture de l'application. --] 63 * [ooConnection host="localhost" port="8101" autoLaunch="true" autoKill="true" profilePath="file:///ooPf01"/] 60 64 * 61 65 * [!-- Pour un server local, lancé automatiquement, en accès pipe, avec pipeName automatique. --] … … 129 133 public static final String TAG_CONN_ATT_AUTOLAUCNH = "autoLaunch"; 130 134 135 public static final String TAG_CONN_ATT_AUTOKILL = "autoKill"; 136 131 137 public static final String TAG_CONN_ATT_MAXCNXATTEMPTS = "maxCnxAttempts"; 132 138 … … 202 208 String vAutoLaunch = pAttributes.getValue(TAG_CONN_ATT_AUTOLAUCNH); 203 209 if (vAutoLaunch != null) vCon.setAutoLaunch(Boolean.parseBoolean(vAutoLaunch)); 210 211 String vAutoKill = pAttributes.getValue(TAG_CONN_ATT_AUTOLAUCNH); 212 if (vAutoKill != null) vCon.setAutoKill(Boolean.parseBoolean(vAutoKill)); 204 213 205 214 String vMaxCnxAttempts = pAttributes.getValue(TAG_CONN_ATT_MAXCNXATTEMPTS); -
trunk/Jav_Transform/src/com/scenari/s/co/transform/oo/impl/OoConnection.java
r15079 r15085 44 44 import java.io.InputStreamReader; 45 45 import java.io.PrintStream; 46 import java.util.HashSet; 46 47 import java.util.Random; 48 import java.util.Set; 47 49 48 50 import com.scenari.s.co.transform.oo.HTransformerOo; … … 75 77 * Implémentation d'une Connection à Oo. 76 78 * 77 * 78 * 79 * Implémentation non thread-safe concue pour être appelée par une seul thread 80 * à la fois (cf {@link OoConnectionPool} pour les accès concurrents). 79 81 */ 80 82 public class OoConnection implements IOoConnection, XEventListener { … … 114 116 protected boolean fAutoLaunch = true; 115 117 118 /** Kill auto du serveur pour les url locales. */ 119 protected boolean fAutoKill = false; 120 116 121 /** Lancement en mode headless du serveur pour les url locales. */ 117 122 protected boolean fHeadless = false; … … 163 168 public OoConnection() { 164 169 super(); 170 } 171 172 /** Gestion du kill des process OO externes lancés par cette JVM. */ 173 static class OoShutdownHook extends Thread { 174 protected Set<OoConnection> fConnectionsToShutdown = new HashSet<OoConnection>(); 175 176 public void run() { 177 //On clone la liste (modifications concurrentes dans vCon.killConnection()). 178 OoConnection[] vConList = (OoConnection[]) fConnectionsToShutdown.toArray(new OoConnection[fConnectionsToShutdown.size()]); 179 for (OoConnection vCon : vConList) { 180 try { 181 if (vCon.isAutoKill()) { 182 LogMgr.publishTrace("kill Scenari OoServer : " + vCon); 183 vCon.killConnection(); 184 } 185 } catch (Exception e) { 186 LogMgr.publishException(e); 187 } 188 } 189 } 190 } 191 192 private static OoShutdownHook sOoShutdownHook = null; 193 194 protected static synchronized void addConnectionToShutdown(OoConnection pCon) { 195 if (sOoShutdownHook == null) { 196 sOoShutdownHook = new OoShutdownHook(); 197 Runtime.getRuntime().addShutdownHook(sOoShutdownHook); 198 } 199 sOoShutdownHook.fConnectionsToShutdown.add(pCon); 200 } 201 202 protected static synchronized void removeConnectionToShutdown(OoConnection pCon) { 203 if (sOoShutdownHook != null) { 204 sOoShutdownHook.fConnectionsToShutdown.remove(pCon); 205 } 165 206 } 166 207 … … 178 219 } 179 220 221 public boolean isLocal() { 222 return fPipeMode || fHost.equals(LOCALHOST) || fHost.equals(LOCALIP); 223 } 224 180 225 public boolean isAutoLaunch() { 181 226 return fAutoLaunch; 182 227 } 183 228 184 public boolean isLocal() {185 return fPipeMode || fHost.equals(LOCALHOST) || fHost.equals(LOCALIP);186 }187 188 229 public void setAutoLaunch(boolean pAutoLaunch) { 189 230 fAutoLaunch = pAutoLaunch; 231 } 232 233 public boolean isAutoKill() { 234 return fAutoKill; 235 } 236 237 public void setAutoKill(boolean pAutoKill) { 238 fAutoKill = pAutoKill; 190 239 } 191 240 … … 335 384 * Doit être appelé par le pool quand une connexion est demandée. 336 385 */ 337 publicvoid reservedInPool() {386 void reservedInPool() { 338 387 fUsageCount++; 339 388 } … … 342 391 * Doit être appelé par le pool quand une connexion est restituée au pool. 343 392 */ 344 publicvoid freedInPool() throws Exception {393 void freedInPool() throws Exception { 345 394 if (fAutoLaunch && fHeadless && fOoProcess != null && fUsageCount >= 5) { 346 fComponentContext = null; 347 fServiceMgr = null; 348 fComponentLoader = null; 349 if (fBridgeComponent != null) { 350 try { 351 fBridgeComponent.dispose(); 352 } catch (Exception e) { 353 LogMgr.publishException(e, ""); 354 } 355 fBridgeComponent = null; 356 } 357 fExternalUriReferenceTranslator = null; 395 killConnection(); 396 } 397 } 398 399 /** Tue cette connection qui pourra ensuite être relancée. */ 400 void killConnection() throws Exception { 401 fComponentContext = null; 402 fServiceMgr = null; 403 fComponentLoader = null; 404 if (fBridgeComponent != null) { 405 try { 406 fBridgeComponent.dispose(); 407 } catch (Exception e) { 408 LogMgr.publishException(e); 409 } 410 fBridgeComponent = null; 411 } 412 fExternalUriReferenceTranslator = null; 413 if (fOoProcess != null) { 358 414 fOoProcess.destroy(); 359 415 fOoProcess = null; 360 fUsageCount = 0; 361 } 416 removeConnectionToShutdown(this); 417 } 418 fUsageCount = 0; 362 419 } 363 420 … … 374 431 fBridgeComponent.dispose(); 375 432 } catch (Exception e) { 376 LogMgr.publishException(e , "");433 LogMgr.publishException(e); 377 434 } 378 435 } … … 521 578 fOoProcess = Runtime.getRuntime().exec(vCmdArray); 522 579 580 //Mémorisation de cette connection server à faire tomber au shutdown de la jvm. 581 addConnectionToShutdown(this); 582 523 583 if (sDebug) { 524 584 pipe(fOoProcess.getInputStream(), System.out, "CO> "); … … 564 624 * On est informé par le serveur oo de son arrêt. 565 625 * 566 */ 567 public synchronized void disposing(EventObject pArg0) { 626 * FIXME utile ? OoConnection n'est pas ThreadSafe, or cette 627 * méthode serait par nature appelée en asynchrone... 628 */ 629 public void disposing(EventObject pArg0) { 568 630 LogMgr.publishTrace("Oo server shutdown."); 569 631 fComponentContext = null; … … 574 636 } 575 637 638 public String toString() { 639 return fPipeMode ? "OoConnection pipe mode : " + fPipeName : "OoConnection socket mode : " + fHost + ":" + fPort; 640 } 576 641 }
Note: See TracChangeset
for help on using the changeset viewer.