[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/callback ...
Ovidiu Feodorov
ovidiu.feodorov at jboss.com
Wed Jan 24 20:07:10 EST 2007
User: ovidiu
Date: 07/01/24 20:07:10
Modified: src/main/org/jboss/remoting/callback Tag: remoting_2_x
CallbackErrorHandler.java
DefaultCallbackErrorHandler.java
ServerInvokerCallbackHandler.java
Log:
various minor reformatting and logging improvments in preparation of http://jira.jboss.org/jira/browse/JBREM-689
Revision Changes Path
No revision
No revision
1.1.10.1 +6 -9 JBossRemoting/src/main/org/jboss/remoting/callback/CallbackErrorHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CallbackErrorHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/callback/CallbackErrorHandler.java,v
retrieving revision 1.1
retrieving revision 1.1.10.1
diff -u -b -r1.1 -r1.1.10.1
--- CallbackErrorHandler.java 3 Jan 2006 06:34:45 -0000 1.1
+++ CallbackErrorHandler.java 25 Jan 2007 01:07:09 -0000 1.1.10.1
@@ -29,20 +29,17 @@
*/
public interface CallbackErrorHandler
{
- public static final String HANDLER_SUBSYSTEM = "handlerSubsystem";
+ static final String HANDLER_SUBSYSTEM = "handlerSubsystem";
/**
- * Sets the configuration for the error handler.
- * This will be called per instance creation on the
+ * Sets the configuration for the error handler. This will be called per instance creation on the
* server side.
- *
- * @param errorHandlerConfig
*/
- public void setConfig(Map errorHandlerConfig);
+ void setConfig(Map errorHandlerConfig);
- public void handleError(Throwable ex) throws Throwable;
+ void handleError(Throwable ex) throws Throwable;
- public void setServerInvoker(ServerInvoker owner);
+ void setServerInvoker(ServerInvoker owner);
- public void setCallbackHandler(ServerInvokerCallbackHandler serverInvokerCallbackHandler);
+ void setCallbackHandler(ServerInvokerCallbackHandler serverInvokerCallbackHandler);
}
\ No newline at end of file
1.3.4.1 +100 -51 JBossRemoting/src/main/org/jboss/remoting/callback/DefaultCallbackErrorHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DefaultCallbackErrorHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/callback/DefaultCallbackErrorHandler.java,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -b -r1.3 -r1.3.4.1
--- DefaultCallbackErrorHandler.java 18 Jul 2006 14:43:33 -0000 1.3
+++ DefaultCallbackErrorHandler.java 25 Jan 2007 01:07:10 -0000 1.3.4.1
@@ -27,46 +27,62 @@
import java.util.Map;
/**
- * Default callback error handler if one not specified. This class
- * will listen for exceptions that occur when trying to deliver callback
- * message to a callback listener from the server. By default, after the fifth
- * exception, it will remove that callback listener from the server invoker handler.
+ * Default callback error handler if one not specified. This class will listen for exceptions that
+ * occur when trying to deliver callback message to a callback listener from the server. By default,
+ * after the fifth exception, it will remove that callback listener from the server invoker handler.
* To set the number of exceptions it will allow before this happens, can set the
* 'callbackErrorsAllowed' attribute within the invoker configuration.
*
* @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
*/
public class DefaultCallbackErrorHandler implements CallbackErrorHandler
{
- private ServerInvoker serverInvoker = null;
- private ServerInvokerCallbackHandler callbackHandler = null;
- private int numOfErrorsAllowed = 5; // defaults to 5 errors before auto clean up
- private int currentNumberOfErrors = 0;
- private String handlerSubsystem = null;
+ // Constants ------------------------------------------------------------------------------------
private static final Logger log = Logger.getLogger(DefaultCallbackErrorHandler.class);
/**
- * Key for setting the number of callback exceptions will be allowed when calling
- * on org.jboss.remoting.callback.InvokerCallbackHandler.handleCallback(Callback callback)
- * before cleaning up the callback listener. This only applies to push callback.
- * The default if this property is not set is five.
+ * Key for setting the number of callback exceptions will be allowed when calling on
+ * org.jboss.remoting.callback.InvokerCallbackHandler.handleCallback(Callback callback)
+ * before cleaning up the callback listener. This only applies to push callback. The default if
+ * this property is not set is five.
*/
public static final String CALLBACK_ERRORS_ALLOWED = "callbackErrorsAllowed";
- /**
- * Sets the configuration for the error handler.
- * This will be called per instance creation on the
- * server side.
- *
- * @param errorHandlerConfig
- */
+
+ // defaults to 5 errors before auto clean up
+ private static final int DEFAULT_NUMBER_OF_ERRORS_ALLOWED = 5;
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ private ServerInvoker serverInvoker;
+ private ServerInvokerCallbackHandler callbackHandler;
+ private int numOfErrorsAllowed;
+ private int currentNumberOfErrors;
+ private String handlerSubsystem;
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public DefaultCallbackErrorHandler()
+ {
+ numOfErrorsAllowed = DEFAULT_NUMBER_OF_ERRORS_ALLOWED;
+ }
+
+ // CallbackErrorHandler implementation ----------------------------------------------------------
+
public void setConfig(Map errorHandlerConfig)
{
- if (errorHandlerConfig != null)
+ if (errorHandlerConfig == null)
{
+ log.warn(this + " got null configuration");
+ return;
+ }
+
// need to get the handler subsystem for if we need to remove the callback listener
- handlerSubsystem = (String) errorHandlerConfig.get(HANDLER_SUBSYSTEM);
+ handlerSubsystem = (String)errorHandlerConfig.get(HANDLER_SUBSYSTEM);
Object value = errorHandlerConfig.get(CALLBACK_ERRORS_ALLOWED);
if (value != null)
@@ -80,34 +96,35 @@
}
catch (NumberFormatException e)
{
- log.warn("Could not convert configuration value for " + CALLBACK_ERRORS_ALLOWED + " (" + stringValue + ") into a numeric value.");
+ log.warn(this + " could not convert configuration value for " +
+ CALLBACK_ERRORS_ALLOWED + " (" + stringValue + ") into a numeric value.");
}
}
else if (value instanceof Integer)
{
- numOfErrorsAllowed = ((Integer) value).intValue();
+ numOfErrorsAllowed = ((Integer)value).intValue();
}
else
{
- log.warn("Could not convert configuration value for " + CALLBACK_ERRORS_ALLOWED + " (" + value + ") into a numeric value. " +
+ log.warn(this + " could not convert configuration value for " +
+ CALLBACK_ERRORS_ALLOWED + " (" + value + ") into a numeric value. " +
"Type of value should be either String or Integer.");
}
}
}
- }
public void handleError(Throwable ex) throws Throwable
{
currentNumberOfErrors++;
- if (log.isTraceEnabled())
- {
- log.trace("Caught " + ex + " exception performing callback. Number of errors sending callbacks is " + currentNumberOfErrors);
- }
+ log.debug(this + " caught " + ex + " exception performing callback. Number of errors " +
+ "sending callbacks is " + currentNumberOfErrors);
if (currentNumberOfErrors >= numOfErrorsAllowed)
{
- log.warn("Reached max number of callback errors allowed. Will clean up callback hander now.");
+ log.warn(this + " reached maximum number of callback errors allowed (" +
+ numOfErrorsAllowed + "). Will clean up callback hander now.");
+
if (serverInvoker != null)
{
serverInvoker.removeCallbackListener(handlerSubsystem, callbackHandler);
@@ -116,17 +133,49 @@
}
else
{
+ log.debug(this + " ignoring the callback error");
throw ex;
}
}
- public void setServerInvoker(ServerInvoker owner)
+ public void setServerInvoker(ServerInvoker serverInvoker)
{
- this.serverInvoker = owner;
+ log.debug(this + " setting server invoker to " + serverInvoker);
+ this.serverInvoker = serverInvoker;
}
- public void setCallbackHandler(ServerInvokerCallbackHandler serverInvokerCallbackHandler)
+ public void setCallbackHandler(ServerInvokerCallbackHandler callbackHandler)
+ {
+ log.debug(this + " setting callback handler to " + callbackHandler);
+ this.callbackHandler = callbackHandler;
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer("DefaultCallbackErrorHandler[");
+
+ if (serverInvoker == null)
+ {
+ sb.append("UNITIALIZED");
+ }
+ else
{
- this.callbackHandler = serverInvokerCallbackHandler;
+ sb.append(serverInvoker);
}
+
+ sb.append(']');
+
+ return sb.toString();
+ }
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+
}
\ No newline at end of file
1.15.2.8 +31 -28 JBossRemoting/src/main/org/jboss/remoting/callback/ServerInvokerCallbackHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ServerInvokerCallbackHandler.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/callback/ServerInvokerCallbackHandler.java,v
retrieving revision 1.15.2.7
retrieving revision 1.15.2.8
diff -u -b -r1.15.2.7 -r1.15.2.8
--- ServerInvokerCallbackHandler.java 20 Jan 2007 08:48:59 -0000 1.15.2.7
+++ ServerInvokerCallbackHandler.java 25 Jan 2007 01:07:10 -0000 1.15.2.8
@@ -127,7 +127,8 @@
private Map idToListenerMap = Collections.synchronizedMap(new HashMap());
- public ServerInvokerCallbackHandler(InvocationRequest invocation, InvokerLocator serverLocator, ServerInvoker owner) throws Exception
+ public ServerInvokerCallbackHandler(InvocationRequest invocation, InvokerLocator serverLocator,
+ ServerInvoker owner) throws Exception
{
if(invocation == null)
{
@@ -585,21 +586,18 @@
/**
* For push callbacks:<p>
+ *
* if asynch == false, behaves the same as handleCallback(Callback callback).<p>
*
* if asynch == true:<p>
- * if serverSide == false, will send the callback to the server invoker on
- * the client side, hand off processing to a separate thread, and return.<p>
*
- * if serverside == true, will hand off to a separate thread the sending
- * of the callback and will then return.<p>
+ * if serverSide == false, will send the callback to the server invoker on the client side,
+ * hand off processing to a separate thread, and return.<p>
*
- * For pull callbacks, behaves the same as handleCallback(Callback callback).<p>
+ * if serverside == true, will hand off to a separate thread the sending of the callback and
+ * will then return.<p>
*
- * @param callback
- * @param asynch
- * @param serverSide
- * @throws HandleCallbackException
+ * For pull callbacks, behaves the same as handleCallback(Callback callback).<p>
*/
public void handleCallback(Callback callback, boolean asynch, boolean serverSide)
throws HandleCallbackException
@@ -628,8 +626,9 @@
}
catch(IOException e)
{
- log.error("Unable to persist callback.", e);
- throw new HandleCallbackException("Unable to persist callback and will not be able to deliver.", e);
+ log.error("Unable to persist callback", e);
+ throw new HandleCallbackException("Unable to persist callback and will not " +
+ "be able to deliver.", e);
}
}
else
@@ -643,6 +642,8 @@
}
else
{
+ // non null callback client
+
try
{
if(trace){ log.debug(this + " got PUSH callback " + callback); }
@@ -683,7 +684,8 @@
if (asynch)
{
if(trace){ log.debug(this + " sending ASYNCHRONOUSLY the callback to the client"); }
- callBackClient.invokeOneway(internalInvocation, callback.getRequestPayload(), serverSide);
+ callBackClient.
+ invokeOneway(internalInvocation, callback.getRequestPayload(), serverSide);
}
else
{
@@ -697,20 +699,21 @@
{
if(callbackErrorHandler != null)
{
+ if (trace) { log.trace(this + " handing the error over to " + callbackErrorHandler); }
callbackErrorHandler.handleError(ex);
}
else
{
- log.debug("Error dispatching callback to handler.", ex);
- throw new HandleCallbackException("Error dispatching callback to handler.", ex);
+ log.debug("Error dispatching callback to handler", ex);
+ throw new HandleCallbackException("Error dispatching callback to handler", ex);
}
}
}
}
- catch(Throwable thr)
+ catch(Throwable t)
{
- log.error("Error handling callback.", thr);
- throw new HandleCallbackException("Error handling callback.", thr);
+ log.error("Error handling callback", t);
+ throw new HandleCallbackException("Error handling callback", t);
}
}
@@ -720,14 +723,13 @@
}
/**
- * Calculates the percentage amount of free memory compared to max memory. The calculations for this
- * is not always acurate. The reason is that total memory used is usually less than the max allowed. Thus,
- * the amount of free memory is relative to the total amount allocated at that point in time. It is not
- * until the total amount of memory allocated is equal to the max it will be allowed to allocate. At this point,
- * the amount of free memory becomes relavent. Therefore, if the memory percentage ceiling is high, it might
- * not trigger until after free memory percentage is well below the ceiling.
- *
- * @return
+ * Calculates the percentage amount of free memory compared to max memory. The calculations for
+ * this is not always acurate. The reason is that total memory used is usually less than the max
+ * allowed. Thus, the amount of free memory is relative to the total amount allocated at that
+ * point in time. It is not until the total amount of memory allocated is equal to the max it
+ * will be allowed to allocate. At this point, the amount of free memory becomes relavent.
+ * Therefore, if the memory percentage ceiling is high, it might not trigger until after free
+ * memory percentage is well below the ceiling.
*/
private boolean shouldPersist()
{
@@ -868,6 +870,7 @@
callBackClient.disconnect();
callBackClient = null;
}
+
if(callbackStore != null)
{
callbackStore.purgeFiles();
More information about the jboss-cvs-commits
mailing list