/*
 * JBoss, Home of Professional Open Source
 * Copyright 2008, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.remoting.spi;

import java.io.IOException;
import org.jboss.remoting.CloseHandler;
import org.jboss.remoting.RequestCancelHandler;
import org.jboss.remoting.RequestContext;
import org.jboss.xnio.log.Logger;

/**
 * Utility methods for Remoting service providers.
 */
public final class SpiUtils {
    private SpiUtils() {}

    private static final Logger log = Logger.getLogger(SpiUtils.class);

    /**
     * Safely notify a reply handler of an exception.
     *
     * @param replyHandler the reply handler
     * @param exception
     */
    public static void safeHandleException(final ReplyHandler replyHandler, final IOException exception) {
        try {
            replyHandler.handleException(exception);
        } catch (Throwable t) {
            log.debug(t, "Failed to properly handle exception");
        }
    }

    /**
     * Safely notify a reply handler of a reply.
     *
     * @param <O> the reply type
     * @param replyHandler the reply handler
     * @param reply the reply
     */
    public static <O> void safeHandleReply(final ReplyHandler replyHandler, final O reply) {
        try {
            replyHandler.handleReply(reply);
        } catch (Throwable t) {
            log.debug(t, "Failed to properly handle reply");
        }
    }

    /**
     * Safely notify a reply handler of a cancellation.
     *
     * @param replyHandler the reply handler
     */
    public static void safeHandleCancellation(final ReplyHandler replyHandler) {
        try {
            replyHandler.handleCancellation();
        } catch (Throwable t) {
            log.debug(t, "Failed to properly handle cancellation");
        }
    }

    /**
     * Safely notify a request listener's cancel handler of cancellation.
     *
     * @param handler the request cancel handler
     * @param requestContext the request context
     */
    public static <O> void safeNotifyCancellation(final RequestCancelHandler<O> handler, final RequestContext<O> requestContext) {
        try {
            handler.notifyCancel(requestContext);
        } catch (Throwable t) {
            log.error(t, "Request cancel handler threw an exception");
        }
    }

    /**
     * Safely handle a close notification.
     *
     * @param <T> the type of the closable resource
     * @param handler the close handler
     * @param closed the object that was closed
     */
    public static <T> void safeHandleClose(final CloseHandler<? super T> handler, final T closed) {
        try {
            handler.handleClose(closed);
        } catch (Throwable t) {
            log.error(t, "Close handler threw an exception");
        }
    }

    public static RemoteRequestContext getBlankRemoteRequestContext() {
        return BLANK_REMOTE_REQUEST_CONTEXT;
    }

    private static final RemoteRequestContext BLANK_REMOTE_REQUEST_CONTEXT = new BlankRemoteRequestContext();

    private static final class BlankRemoteRequestContext implements RemoteRequestContext {
        public void cancel() {
        }
    }
}


@@ -1323,16 +1323,17 @@
 Utils %7B%0A
+%0A
     priv
@@ -1383,17 +1383,19 @@
  Logger 
-l
+heL
 og = Log
@@ -1412,22 +1412,43 @@
 ger(
-SpiUtils.class
+%22org.jboss.remoting.handler-errors%22
 );%0A%0A
@@ -1803,33 +1803,35 @@
 ) %7B%0A            
-l
+heL
 og.debug(t, %22Fai
@@ -2251,33 +2251,35 @@
 ) %7B%0A            
-l
+heL
 og.debug(t, %22Fai
@@ -2637,17 +2637,19 @@
         
-l
+heL
 og.debug
@@ -3138,33 +3138,35 @@
 ) %7B%0A            
-l
+heL
 og.error(t, %22Req
@@ -3629,17 +3629,19 @@
         
-l
+heL
 og.error

Change the logger to be specific to handler errors