| 1 |
package org.astrogrid.samp.client; |
| 2 |
|
| 3 |
import java.util.logging.Logger; |
| 4 |
import org.astrogrid.samp.Client; |
| 5 |
import org.astrogrid.samp.ErrInfo; |
| 6 |
import org.astrogrid.samp.Message; |
| 7 |
import org.astrogrid.samp.Response; |
| 8 |
import org.astrogrid.samp.SampUtils; |
| 9 |
import org.astrogrid.samp.client.HubConnection; |
| 10 |
|
| 11 |
/** |
| 12 |
* ResultHandler implementation which outputs some information about |
| 13 |
* responses received through the logging system. |
| 14 |
* |
| 15 |
* @author Mark Taylor |
| 16 |
* @since 12 Nov 2008 |
| 17 |
*/ |
| 18 |
public class LogResultHandler implements ResultHandler { |
| 19 |
|
| 20 |
private final String mtype_; |
| 21 |
private static final Logger logger_ = |
| 22 |
Logger.getLogger( LogResultHandler.class.getName() ); |
| 23 |
|
| 24 |
/** |
| 25 |
* Constructor. |
| 26 |
* |
| 27 |
* @param msg message which was sent |
| 28 |
*/ |
| 29 |
public LogResultHandler( Message msg ) { |
| 30 |
mtype_ = msg.getMType(); |
| 31 |
} |
| 32 |
|
| 33 |
public void result( Client client, Response response ) { |
| 34 |
if ( response.isOK() ) { |
| 35 |
logger_.info( mtype_ + ": successful send to " + client ); |
| 36 |
} |
| 37 |
else { |
| 38 |
logger_.warning( mtype_ + ": error sending to " + client ); |
| 39 |
ErrInfo errInfo = response.getErrInfo(); |
| 40 |
if ( errInfo != null ) { |
| 41 |
String errortxt = errInfo.getErrortxt(); |
| 42 |
if ( errortxt != null ) { |
| 43 |
logger_.warning( errortxt ); |
| 44 |
} |
| 45 |
logger_.info( SampUtils.formatObject( errInfo, 3 ) ); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
public void done() { |
| 51 |
} |
| 52 |
} |