Project Report: fawkez

Packagesummary org.jcoderz.commons.util

org.jcoderz.commons.util.JmsUtil

LineHitsNoteSource
1  /*
2   * $Id: JmsUtil.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.util;
34  
35  import java.util.logging.Level;
36  import java.util.logging.Logger;
37  
38  import javax.jms.Connection;
39  import javax.jms.JMSException;
40  import javax.jms.MessageProducer;
41  import javax.jms.Session;
42  
43  /**
44   * Collects some JMS utility functions.
45   *
46   */
47 (1)public final class JmsUtil
48  {
49     /** The full qualified name of this class. */
500    private static final String CLASSNAME = JmsUtil.class.getName();
51  
52     /** The logger to use. */
530    private static final Logger logger = Logger.getLogger(CLASSNAME);
54  
55     /**
56      * Constructor.
57      */
58     private JmsUtil ()
590    {
60        // Utility class -- only static methods
610    }
62  
63     /**
64      * Closes the jms session (safe).
65      *
66      * This method tries to close the given session and if an
67      * {@link JMSException} occurs a message with the level {@link Level#FINE} is
68      * logged. It's safe to pass a <code>null</code> reference for the argument.
69      *
70      * @param session The jms session that should be closed.
71      */
72     public static void close (Session session)
73     {
740       if (session != null)
75        {
76           try
77           {
780             session.close();
79           }
800          catch (JMSException e)
81           {
820             logCloseFailedWarningMessage(
83                    Session.class, session.getClass(), e);
840          }
85        }
860    }
87  
88     /**
89      * Closes the jms connection (safe).
90      *
91      * This method tries to close the given connection and if an
92      * {@link JMSException} occurs a message with the level {@link Level#FINE} is
93      * logged. It's safe to pass a <code>null</code> reference for the argument.
94      *
95      * @param connection The connection to be closed.
96      */
97     public static void close (Connection connection)
98     {
990       if (connection != null)
100        {
101           try
102           {
1030             connection.close();
104           }
1050          catch (JMSException e)
106           {
1070             logCloseFailedWarningMessage(
108                    Connection.class, connection.getClass(), e);
1090          }
110        }
1110    }
112  
113     /**
114      * Closes the jms message producer (safe).
115      *
116      * This method tries to close the given message producer and if an
117      * {@link JMSException} occurs a message with the level {@link Level#FINE} is
118      * logged. It's safe to pass a <code>null</code> reference for the argument.
119      *
120      * @param producer The message producer to be closed.
121      */
122     public static void close (MessageProducer producer)
123     {
1240       if (producer != null)
125        {
126           try
127           {
1280             producer.close();
129           }
1300          catch (JMSException e)
131           {
1320             logCloseFailedWarningMessage(
133                    MessageProducer.class, producer.getClass(), e);
1340          }
135        }
1360    }
137  
138     private static void logCloseFailedWarningMessage (Class resource,
139           Class clazz, JMSException x)
140     {
1410       logger.log(Level.FINE, "Error while closing " + resource.getName() + ": "
142              + clazz.getName() + ".close()", x);
1430    }
144  }

Findings in this File

c (1) 47 : 0 Type Javadoc comment is missing an @author tag.