Changeset 15085


Ignore:
Timestamp:
03/09/10 17:30:59 (2 years ago)
Author:
sys
Message:

OoConnection : ajout paramètre autoKill

Location:
trunk/Jav_Transform/src/com/scenari/s/co/transform/oo
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Jav_Transform/src/com/scenari/s/co/transform/oo/IOoConnection.java

    r14602 r15085  
    4444 */ 
    4545public interface IOoConnection { 
    46          
     46 
    4747        public void setAutoLaunch(boolean pAutoLaunch); 
    48          
     48 
     49        public void setAutoKill(boolean pAutoKill); 
     50 
    4951        public void setHost(String pHost); 
    50          
     52 
    5153        public void setPort(int pPort); 
    52          
     54 
    5355        public void setMaxCnxAttempts(int pMaxAttempts); 
    54          
     56 
    5557        public void setPipeMode(boolean pPipeMode); 
    56          
     58 
    5759        public void setPipeName(String pPipeName); 
    58          
     60 
    5961        public void setProfilePath(String pProfilePath); 
    60          
     62 
    6163        public void setHeadless(boolean pHeadless); 
    62          
     64 
    6365        public void setReCheckInterval(long pMs); 
    64          
     66 
    6567} 
  • trunk/Jav_Transform/src/com/scenari/s/co/transform/oo/OoConnectionPoolLoader.java

    r15083 r15085  
    5858 *   [!-- Pour un server local, lancé automatiquement, en accès socket TCP/IP. --] 
    5959 *   [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"/] 
    6064 *    
    6165 *   [!-- Pour un server local, lancé automatiquement, en accès pipe, avec pipeName automatique. --] 
     
    129133        public static final String TAG_CONN_ATT_AUTOLAUCNH = "autoLaunch"; 
    130134 
     135        public static final String TAG_CONN_ATT_AUTOKILL = "autoKill"; 
     136 
    131137        public static final String TAG_CONN_ATT_MAXCNXATTEMPTS = "maxCnxAttempts"; 
    132138 
     
    202208                        String vAutoLaunch = pAttributes.getValue(TAG_CONN_ATT_AUTOLAUCNH); 
    203209                        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)); 
    204213 
    205214                        String vMaxCnxAttempts = pAttributes.getValue(TAG_CONN_ATT_MAXCNXATTEMPTS); 
  • trunk/Jav_Transform/src/com/scenari/s/co/transform/oo/impl/OoConnection.java

    r15079 r15085  
    4444import java.io.InputStreamReader; 
    4545import java.io.PrintStream; 
     46import java.util.HashSet; 
    4647import java.util.Random; 
     48import java.util.Set; 
    4749 
    4850import com.scenari.s.co.transform.oo.HTransformerOo; 
     
    7577 * Implémentation d'une Connection à Oo. 
    7678 *  
    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). 
    7981 */ 
    8082public class OoConnection implements IOoConnection, XEventListener { 
     
    114116        protected boolean fAutoLaunch = true; 
    115117 
     118        /** Kill auto du serveur pour les url locales. */ 
     119        protected boolean fAutoKill = false; 
     120 
    116121        /** Lancement en mode headless du serveur pour les url locales. */ 
    117122        protected boolean fHeadless = false; 
     
    163168        public OoConnection() { 
    164169                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                } 
    165206        } 
    166207 
     
    178219        } 
    179220 
     221        public boolean isLocal() { 
     222                return fPipeMode || fHost.equals(LOCALHOST) || fHost.equals(LOCALIP); 
     223        } 
     224 
    180225        public boolean isAutoLaunch() { 
    181226                return fAutoLaunch; 
    182227        } 
    183228 
    184         public boolean isLocal() { 
    185                 return fPipeMode || fHost.equals(LOCALHOST) || fHost.equals(LOCALIP); 
    186         } 
    187  
    188229        public void setAutoLaunch(boolean pAutoLaunch) { 
    189230                fAutoLaunch = pAutoLaunch; 
     231        } 
     232 
     233        public boolean isAutoKill() { 
     234                return fAutoKill; 
     235        } 
     236 
     237        public void setAutoKill(boolean pAutoKill) { 
     238                fAutoKill = pAutoKill; 
    190239        } 
    191240 
     
    335384         * Doit être appelé par le pool quand une connexion est demandée. 
    336385         */ 
    337         public void reservedInPool() { 
     386        void reservedInPool() { 
    338387                fUsageCount++; 
    339388        } 
     
    342391         * Doit être appelé par le pool quand une connexion est restituée au pool. 
    343392         */ 
    344         public void freedInPool() throws Exception { 
     393        void freedInPool() throws Exception { 
    345394                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) { 
    358414                        fOoProcess.destroy(); 
    359415                        fOoProcess = null; 
    360                         fUsageCount = 0; 
    361                 } 
     416                        removeConnectionToShutdown(this); 
     417                } 
     418                fUsageCount = 0; 
    362419        } 
    363420 
     
    374431                                fBridgeComponent.dispose(); 
    375432                        } catch (Exception e) { 
    376                                 LogMgr.publishException(e, ""); 
     433                                LogMgr.publishException(e); 
    377434                        } 
    378435                } 
     
    521578                        fOoProcess = Runtime.getRuntime().exec(vCmdArray); 
    522579 
     580                        //Mémorisation de cette connection server à faire tomber au shutdown de la jvm. 
     581                        addConnectionToShutdown(this); 
     582 
    523583                        if (sDebug) { 
    524584                                pipe(fOoProcess.getInputStream(), System.out, "CO> "); 
     
    564624         * On est informé par le serveur oo de son arrêt. 
    565625         * 
    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) { 
    568630                LogMgr.publishTrace("Oo server shutdown."); 
    569631                fComponentContext = null; 
     
    574636        } 
    575637 
     638        public String toString() { 
     639                return fPipeMode ? "OoConnection pipe mode : " + fPipeName : "OoConnection socket mode : " + fHost + ":" + fPort; 
     640        } 
    576641} 
Note: See TracChangeset for help on using the changeset viewer.