tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp ReplicationTransmitter.java SimpleTcpCluster.java
Date Wed, 01 Dec 2004 09:41:11 GMT
pero        2004/12/01 01:41:11

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster/deploy
                        FarmWarDeployer.java FileMessageFactory.java
                        WarWatcher.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        ReplicationTransmitter.java SimpleTcpCluster.java
  Log:
  Fix some log.
  Change some names
  
  Revision  Changes    Path
  1.6       +8 -8      jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/deploy/FarmWarDeployer.java
  
  Index: FarmWarDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/deploy/FarmWarDeployer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FarmWarDeployer.java	27 Nov 2004 21:16:14 -0000	1.5
  +++ FarmWarDeployer.java	1 Dec 2004 09:41:11 -0000	1.6
  @@ -82,11 +82,11 @@
       private int count = 0;
   
       /**
  -     * Frequency of the Form deploydir check. Cluster wide deployment will be
  +     * Frequency of the Farm watchDir check. Cluster wide deployment will be
        * done once for the specified amount of backgrondProcess calls (ie, the
        * lower the amount, the most often the checks will occur).
        */
  -    protected int processExpiresFrequency = 2;
  +    protected int processDeployFrequency = 2;
   
       /**
        * Path where context descriptors should be deployed.
  @@ -562,7 +562,7 @@
        */
       public void backgroundProcess() {
           if (started) {
  -            count = (count + 1) % processExpiresFrequency;
  +            count = (count + 1) % processDeployFrequency;
               if (count == 0 && watchEnabled) {
                   watcher.check();
               }
  @@ -666,24 +666,24 @@
       /**
        * Return the frequency of watcher checks.
        */
  -    public int getProcessExpiresFrequency() {
  +    public int getProcessDeployFrequency() {
   
  -        return (this.processExpiresFrequency);
  +        return (this.processDeployFrequency);
   
       }
   
       /**
        * Set the watcher checks frequency.
        * 
  -     * @param processExpiresFrequency
  +     * @param processDeployFrequency
        *            the new manager checks frequency
        */
  -    public void setProcessExpiresFrequency(int processExpiresFrequency) {
  +    public void setProcessDeployFrequency(int processExpiresFrequency) {
   
           if (processExpiresFrequency <= 0) {
               return;
           }
  -        this.processExpiresFrequency = processExpiresFrequency;
  +        this.processDeployFrequency = processExpiresFrequency;
       }
   
       /**
  
  
  
  1.3       +180 -124  jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java
  
  Index: FileMessageFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/deploy/FileMessageFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileMessageFactory.java	27 Nov 2004 21:10:20 -0000	1.2
  +++ FileMessageFactory.java	1 Dec 2004 09:41:11 -0000	1.3
  @@ -15,19 +15,24 @@
    */
   
   package org.apache.catalina.cluster.deploy;
  +
   import java.io.File;
   import java.io.IOException;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
   import java.io.FileNotFoundException;
  +
   /**
  - * This factory is used to read files and write files by splitting them up into smaller
  - * messages. So that entire files don't have to be read into memory.<BR>
  + * This factory is used to read files and write files by splitting them up into
  + * smaller messages. So that entire files don't have to be read into memory.
  + * <BR>
    * The factory can be used as a reader or writer but not both at the same time.
  - * When done reading or writing the factory will close the input or output streams
  - * and mark the factory as closed. It is not possible to use it after that.<BR>
  - * To force a cleanup, call cleanup() from the calling object.<BR>
  - * This class is not thread safe. 
  + * When done reading or writing the factory will close the input or output
  + * streams and mark the factory as closed. It is not possible to use it after
  + * that. <BR>
  + * To force a cleanup, call cleanup() from the calling object. <BR>
  + * This class is not thread safe.
  + * 
    * @author Filip Hanik
    * @version 1.0
    */
  @@ -35,122 +40,138 @@
       /*--Static Variables----------------------------------------*/
       public static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
               .getLog(FileMessageFactory.class);
  -   
  +
       /**
        * The number of bytes that we read from file
        */
  -    public static final int READ_SIZE = 1024*10; //10kb
  -    
  +    public static final int READ_SIZE = 1024 * 10; //10kb
  +
       /**
        * The file that we are reading/writing
        */
       protected File file = null;
  -    
  +
       /**
  -     * True means that we are writing with this factory.
  -     * False means that we are reading with this factory
  +     * True means that we are writing with this factory. False means that we are
  +     * reading with this factory
        */
       protected boolean openForWrite;
  -    
  +
       /**
        * Once the factory is used, it can not be reused.
        */
       protected boolean closed = false;
  -    
  +
       /**
  -     * When openForWrite=false, the input stream 
  -     * is held by this variable
  +     * When openForWrite=false, the input stream is held by this variable
        */
       protected FileInputStream in;
  -    
  +
       /**
  -     * When openForWrite=true, the output stream 
  -     * is held by this variable
  +     * When openForWrite=true, the output stream is held by this variable
        */
       protected FileOutputStream out;
  -    
  +
       /**
        * The number of messages we have read or written
        */
       protected int nrOfMessagesProcessed = 0;
  -    
  +
       /**
        * The total size of the file
        */
       protected long size = 0;
  -    
  +
       /**
        * The total number of packets that we split this file into
        */
       protected long totalNrOfMessages = 0;
  -    
  +
       /**
        * The bytes that we hold the data in, not thread safe.
        */
       protected byte[] data = new byte[READ_SIZE];
  -    
  +
       /**
  -     * Private constructor, either instantiates a factory to read or write.<BR>
  -     * When openForWrite==true, then a the file, f, will be created and an output 
  -     * stream is opened to write to it.<BR>
  -     * When openForWrite==false, an input stream is opened, the file has to exist.
  -     * @param f File - the file to be read/written
  -     * @param openForWrite boolean - true means we are writing to the file, false 
  -     * means we are reading from the file
  -     * @throws FileNotFoundException - if the file to be read doesn't exist
  -     * @throws IOException - if the system fails to open input/output streams to the file
  -     * or if it fails to create the file to be written to.
  +     * Private constructor, either instantiates a factory to read or write. <BR>
  +     * When openForWrite==true, then a the file, f, will be created and an
  +     * output stream is opened to write to it. <BR>
  +     * When openForWrite==false, an input stream is opened, the file has to
  +     * exist.
  +     * 
  +     * @param f
  +     *            File - the file to be read/written
  +     * @param openForWrite
  +     *            boolean - true means we are writing to the file, false means
  +     *            we are reading from the file
  +     * @throws FileNotFoundException -
  +     *             if the file to be read doesn't exist
  +     * @throws IOException -
  +     *             if the system fails to open input/output streams to the file
  +     *             or if it fails to create the file to be written to.
        */
  -    private FileMessageFactory(File f, boolean openForWrite) 
  -        throws FileNotFoundException, IOException{
  +    private FileMessageFactory(File f, boolean openForWrite)
  +            throws FileNotFoundException, IOException {
           this.file = f;
           this.openForWrite = openForWrite;
  -        if(log.isDebugEnabled())
  -            log.debug("open file " + f + " write " +  openForWrite);
  -        if ( openForWrite ) {
  -            if (!file.exists()) file.createNewFile();
  +        if (log.isDebugEnabled())
  +            log.debug("open file " + f + " write " + openForWrite);
  +        if (openForWrite) {
  +            if (!file.exists())
  +                file.createNewFile();
               out = new FileOutputStream(f);
  -          } else {
  +        } else {
               size = file.length();
               totalNrOfMessages = (size / READ_SIZE) + 1;
               in = new FileInputStream(f);
           }//end if
  -            
  +
       }
  -    
  +
  +    /**
  +     * Creates a factory to read or write from a file. When opening for read,
  +     * the readMessage can be invoked, and when opening for write the
  +     * writeMessage can be invoked.
  +     * 
  +     * @param f
  +     *            File - the file to be read or written
  +     * @param openForWrite
  +     *            boolean - true, means we are writing to the file, false means
  +     *            we are reading from it
  +     * @throws FileNotFoundException -
  +     *             if the file to be read doesn't exist
  +     * @throws IOException -
  +     *             if it fails to create the file that is to be written
  +     * @return FileMessageFactory
  +     */
  +    public static FileMessageFactory getInstance(File f, boolean openForWrite)
  +            throws FileNotFoundException, IOException {
  +        return new FileMessageFactory(f, openForWrite);
  +    }
  +
       /**
  -     * Creates a factory to read or write from a file.
  -     * When opening for read, the readMessage can be invoked, and when
  -     * opening for write the writeMessage can be invoked.
  -     * @param f File - the file to be read or written
  -     * @param openForWrite boolean - true, means we are writing to the file, false means
we are 
  -     * reading from it 
  -     * @throws FileNotFoundException - if the file to be read doesn't exist
  -     * @throws IOException - if it fails to create the file that is to be written
  -     * @return FileMessageFactory 
  -     */
  -    public static FileMessageFactory getInstance(File f, boolean openForWrite) 
  -        throws FileNotFoundException, IOException {
  -        return new FileMessageFactory(f,openForWrite);
  -    }
  -    
  -    /**
  -     * Reads file data into the file message and sets the 
  -     * size, totalLength, totalNrOfMsgs and the message number<BR>
  -     * If EOF is reached, the factory returns null, and closes itself,
  -     * otherwise the same message is returned as was passed in.
  -     * This makes sure that not more memory is ever used. 
  -     * To remember, neither the file message or the factory are thread safe.
  -     * dont hand off the message to one thread and read the same with another. 
  -     * @param f FileMessage - the message to be populated with file data
  -     * @throws IllegalArgumentException - if the factory is for writing or is closed
  -     * @throws IOException - if a file read exception occurs
  -     * @return FileMessage - returns the same message passed in as a parameter, or null
if EOF
  +     * Reads file data into the file message and sets the size, totalLength,
  +     * totalNrOfMsgs and the message number <BR>
  +     * If EOF is reached, the factory returns null, and closes itself, otherwise
  +     * the same message is returned as was passed in. This makes sure that not
  +     * more memory is ever used. To remember, neither the file message or the
  +     * factory are thread safe. dont hand off the message to one thread and read
  +     * the same with another.
  +     * 
  +     * @param f
  +     *            FileMessage - the message to be populated with file data
  +     * @throws IllegalArgumentException -
  +     *             if the factory is for writing or is closed
  +     * @throws IOException -
  +     *             if a file read exception occurs
  +     * @return FileMessage - returns the same message passed in as a parameter,
  +     *         or null if EOF
        */
  -    public FileMessage readMessage(FileMessage f) throws IllegalArgumentException, IOException
{
  +    public FileMessage readMessage(FileMessage f)
  +            throws IllegalArgumentException, IOException {
           checkState(false);
           int length = in.read(data);
  -        if ( length == -1 ) {
  +        if (length == -1) {
               cleanup();
               return null;
           } else {
  @@ -161,36 +182,64 @@
               return f;
           }//end if
       }
  -    
  +
       /**
  -     * Writes a message to file. If (msg.getMessageNumber() == msg.getTotalNrOfMsgs())
  -     * the output stream will be closed after writing.  
  -     * @param msg FileMessage - message containing data to be written
  -     * @throws IllegalArgumentException - if the factory is opened for read or closed
  -     * @throws IOException - if a file write error occurs
  -     * @return returns true if the file is complete and outputstream is closed, false otherwise.
  -     */
  -    public boolean writeMessage(FileMessage msg) throws IllegalArgumentException, IOException
{
  -        if ( !openForWrite ) throw new IllegalArgumentException("Can't write message, this
factory is reading.");
  -        if(log.isTraceEnabled())
  -            log.trace("Message " + msg + " data " + msg.getData() + " data length " + msg.getDataLength()
+ " out " + out );
  -        out.write(msg.getData(),0,msg.getDataLength());
  -        nrOfMessagesProcessed++;
  -        out.flush();
  -        if ( msg.getMessageNumber() == msg.getTotalNrOfMsgs() ) {
  -            out.close();
  -            cleanup();
  -            return true;
  -        }//end if
  +     * Writes a message to file. If (msg.getMessageNumber() ==
  +     * msg.getTotalNrOfMsgs()) the output stream will be closed after writing.
  +     * 
  +     * @param msg
  +     *            FileMessage - message containing data to be written
  +     * @throws IllegalArgumentException -
  +     *             if the factory is opened for read or closed
  +     * @throws IOException -
  +     *             if a file write error occurs
  +     * @return returns true if the file is complete and outputstream is closed,
  +     *         false otherwise.
  +     */
  +    public boolean writeMessage(FileMessage msg)
  +            throws IllegalArgumentException, IOException {
  +        if (!openForWrite)
  +            throw new IllegalArgumentException(
  +                    "Can't write message, this factory is reading.");
  +        if (log.isDebugEnabled())
  +            log.debug("Message " + msg + " data " + msg.getData()
  +                    + " data length " + msg.getDataLength() + " out " + out);
  +        if (out != null) {
  +            out.write(msg.getData(), 0, msg.getDataLength());
  +            nrOfMessagesProcessed++;
  +            out.flush();
  +            if (msg.getMessageNumber() == msg.getTotalNrOfMsgs()) {
  +                out.close();
  +                cleanup();
  +                return true;
  +            }//end if
  +        } else {
  +            if (log.isWarnEnabled())
  +                log.warn("Receive Message again -- Sender ActTimeout to short [ path: "
  +                                + msg.getContextPath()
  +                                + " war: "
  +                                + msg.getFileName()
  +                                + " data: "
  +                                + msg.getData()
  +                                + " data length: " + msg.getDataLength() + " ]");
  +        }
           return false;
       }//writeMessage
  -    
  +
       /**
        * Closes the factory, its streams and sets all its references to null
        */
       public void cleanup() {
  -        if ( in != null ) try { in.close(); } catch ( Exception ignore ){}
  -        if ( out != null ) try { out.close(); } catch ( Exception ignore ){}
  +        if (in != null)
  +            try {
  +                in.close();
  +            } catch (Exception ignore) {
  +            }
  +        if (out != null)
  +            try {
  +                out.close();
  +            } catch (Exception ignore) {
  +            }
           in = null;
           out = null;
           size = 0;
  @@ -199,57 +248,64 @@
           nrOfMessagesProcessed = 0;
           totalNrOfMessages = 0;
       }
  -    
  +
       /**
  -     * Check to make sure the factory is able to perform the 
  -     * function it is asked to do. Invoked by readMessage/writeMessage before
  -     * those methods proceed.
  -     * @param openForWrite boolean
  +     * Check to make sure the factory is able to perform the function it is
  +     * asked to do. Invoked by readMessage/writeMessage before those methods
  +     * proceed.
  +     * 
  +     * @param openForWrite
  +     *            boolean
        * @throws IllegalArgumentException
        */
  -    protected void checkState(boolean openForWrite) throws IllegalArgumentException {
  -        if ( this.openForWrite != openForWrite ) {
  +    protected void checkState(boolean openForWrite)
  +            throws IllegalArgumentException {
  +        if (this.openForWrite != openForWrite) {
               cleanup();
  -            if ( openForWrite )  
  -                throw new IllegalArgumentException("Can't write message, this factory is
reading.");
  -            else 
  -                throw new IllegalArgumentException("Can't read message, this factory is
writing.");
  +            if (openForWrite)
  +                throw new IllegalArgumentException(
  +                        "Can't write message, this factory is reading.");
  +            else
  +                throw new IllegalArgumentException(
  +                        "Can't read message, this factory is writing.");
           }
  -        if ( this.closed ) {
  +        if (this.closed) {
               cleanup();
               throw new IllegalArgumentException("Factory has been closed.");
           }
       }
  -        
  +
       /**
        * Example usage.
  -     * @param args String[], args[0] - read from filename, args[1] write to filename
  +     * 
  +     * @param args
  +     *            String[], args[0] - read from filename, args[1] write to
  +     *            filename
        * @throws Exception
        */
       public static void main(String[] args) throws Exception {
  -        
  -        
  -        System.out.println("Usage: FileMessageFactory fileToBeRead fileToBeWritten");
  -        System.out.println("Usage: This will make a copy of the file on the local file
system");
  -        FileMessageFactory read = getInstance(new File(args[0]),false);
  -        FileMessageFactory write = getInstance(new File(args[1]),true);
  -        FileMessage msg = new FileMessage(null,args[0],args[0]);
  +
  +        System.out
  +                .println("Usage: FileMessageFactory fileToBeRead fileToBeWritten");
  +        System.out
  +                .println("Usage: This will make a copy of the file on the local file system");
  +        FileMessageFactory read = getInstance(new File(args[0]), false);
  +        FileMessageFactory write = getInstance(new File(args[1]), true);
  +        FileMessage msg = new FileMessage(null, args[0], args[0]);
           msg = read.readMessage(msg);
  -        System.out.println("Expecting to write " + msg.getTotalNrOfMsgs()+" messages.");
  +        System.out.println("Expecting to write " + msg.getTotalNrOfMsgs()
  +                + " messages.");
           int cnt = 0;
  -        while ( msg != null ) {
  +        while (msg != null) {
               write.writeMessage(msg);
               cnt++;
               msg = read.readMessage(msg);
           }//while
  -        System.out.println("Actually wrote " + cnt+" messages.");
  +        System.out.println("Actually wrote " + cnt + " messages.");
       }///main
  -    
  +
       public File getFile() {
           return file;
       }
  -    
  -    
  -    
   
  -}
  +}
  \ No newline at end of file
  
  
  
  1.4       +12 -12    jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java
  
  Index: WarWatcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/deploy/WarWatcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WarWatcher.java	27 Nov 2004 21:10:20 -0000	1.3
  +++ WarWatcher.java	1 Dec 2004 09:41:11 -0000	1.4
  @@ -43,7 +43,7 @@
       /**
        * Directory to watch for war files
        */
  -    protected File deployDir = null;
  +    protected File watchDir = null;
   
       /**
        * Parent to be notified of changes
  @@ -60,9 +60,9 @@
       public WarWatcher() {
       }
   
  -    public WarWatcher(FileChangeListener listener, File deployDir) {
  +    public WarWatcher(FileChangeListener listener, File watchDir) {
           this.listener = listener;
  -        this.deployDir = deployDir;
  +        this.watchDir = watchDir;
       }
   
       /*--Logic---------------------------------------------------*/
  @@ -72,8 +72,8 @@
        */
       public void check() {
           if (log.isInfoEnabled())
  -            log.info("check cluster wars at " + deployDir);
  -        File[] list = deployDir.listFiles(new WarFilter());
  +            log.info("check cluster wars at " + watchDir);
  +        File[] list = watchDir.listFiles(new WarFilter());
           if (list == null)
               list = new File[0];
           //first make sure all the files are listed in our current status
  @@ -118,18 +118,18 @@
       }
   
       /**
  -     * @return Returns the deployDir.
  +     * @return Returns the watchDir.
        */
  -    public File getDeployDir() {
  -        return deployDir;
  +    public File getWatchDir() {
  +        return watchDir;
       }
   
       /**
  -     * @param deployDir
  -     *            The deployDir to set.
  +     * @param watchDir
  +     *            The watchDir to set.
        */
  -    public void setDeployDir(File deployDir) {
  -        this.deployDir = deployDir;
  +    public void setWatchDir(File watchDir) {
  +        this.watchDir = watchDir;
       }
   
       /**
  
  
  
  1.19      +11 -8     jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ReplicationTransmitter.java
  
  Index: ReplicationTransmitter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ReplicationTransmitter.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ReplicationTransmitter.java	11 Nov 2004 14:47:27 -0000	1.18
  +++ ReplicationTransmitter.java	1 Dec 2004 09:41:11 -0000	1.19
  @@ -62,21 +62,24 @@
       public synchronized void add(Member member)
       {
           try {
  -            IDataSender sender = IDataSenderFactory.getIDataSender(
  -                replicationMode, member);
  -            String key = sender.getAddress().getHostAddress() + ":" +
  -                sender.getPort();
  -            if (!map.containsKey(key))
  -                map.put(sender.getAddress().getHostAddress() + ":" +
  -                        sender.getPort(), sender);
  +            String key = getKey(member);
  +            if (!map.containsKey(key)) {
  +                IDataSender sender = IDataSenderFactory.getIDataSender(
  +                        replicationMode, member);
  +                map.put(key, sender);
  +            }
           }catch ( java.io.IOException x ) {
               log.error("Unable to create and add a IDataSender object.",x);
           }
       }//add
   
  +    private String getKey(Member member) {
  +        return member.getHost() + ":" + member.getPort();
  +    }
  +    
       public synchronized void remove(Member member)
       {
  -        String key = member.getHost() + ":" + member.getPort();
  +        String key = getKey(member);
           IDataSender toberemoved = (IDataSender) map.get(key);
           if (toberemoved == null)return;
           toberemoved.disconnect();
  
  
  
  1.56      +3 -5      jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java
  
  Index: SimpleTcpCluster.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- SimpleTcpCluster.java	27 Nov 2004 21:10:20 -0000	1.55
  +++ SimpleTcpCluster.java	1 Dec 2004 09:41:11 -0000	1.56
  @@ -389,9 +389,6 @@
               try {
                   if ( clusterDeployer != null ) {
                       clusterDeployer.setCluster(this);
  -                    // Object deployer = IntrospectionUtils.getProperty(getContainer(),
"deployer");
  -                    // FIXME: clusterDeployer.setDeployer( (org.apache.catalina.Deployer)
deployer);
  -                    // clusterDeployer.setDeployer( deployer);
                       clusterDeployer.start();
                   }
               } catch (Throwable x) {
  @@ -494,7 +491,8 @@
   
       public void memberDisappeared(Member member)
       {
  -        log.info("Received member disappeared:"+member);
  +        if(log.isInfoEnabled())
  +            log.info("Received member disappeared:"+member);
           try
           {
               clusterSender.remove(member);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message