@@ -147,16 +147,20 @@ protected Request(Version ver, long seq, long agentId, long mgmtId, long via, sh
147147 _content = content ;
148148 }
149149
150- public Request (long seq , long agentId , long mgmtId , final Command command , boolean fromServer ) {
151- this (seq , agentId , mgmtId , new Command [] { command }, true , fromServer );
150+ public Request (long agentId , long mgmtId , Command command , boolean fromServer ) {
151+ this (agentId , mgmtId , new Command [] { command }, true , fromServer );
152152 }
153153
154- public Request (long seq , long agentId , long mgmtId , Command [] cmds , boolean stopOnError , boolean fromServer ) {
155- this (Version .v3 , seq , agentId , mgmtId , (short ) 0 , cmds );
154+ public Request (long agentId , long mgmtId , Command [] cmds , boolean stopOnError , boolean fromServer ) {
155+ this (Version .v1 , - 1l , agentId , mgmtId , (short )0 , cmds );
156156 setStopOnError (stopOnError );
157157 setFromServer (fromServer );
158158 }
159159
160+ public void setSequence (long seq ) {
161+ _seq = seq ;
162+ }
163+
160164 protected void setInSequence (Command [] cmds ) {
161165 if (cmds == null ) {
162166 return ;
@@ -316,31 +320,55 @@ protected short getFlags() {
316320 return (short ) (((this instanceof Response ) ? FLAG_RESPONSE : FLAG_REQUEST ) | _flags );
317321 }
318322
319- public void log (long agentId , String msg ) {
323+ public void logD (String msg ) {
324+ logD (msg , true );
325+ }
326+
327+ public void logD (String msg , boolean logContent ) {
328+ if (s_logger .isDebugEnabled ()) {
329+ s_logger .debug (log (msg , logContent ));
330+ }
331+ }
332+
333+ public void logT (String msg , boolean logD ) {
334+ if (s_logger .isTraceEnabled ()) {
335+ s_logger .trace (log (msg , true ));
336+ } else if (logD && s_logger .isDebugEnabled ()) {
337+ s_logger .debug (log (msg , false ));
338+ }
339+ }
340+
341+ public String log (String msg , boolean logContent ) {
320342 StringBuilder buf = new StringBuilder ("Seq " );
321343 buf .append (_agentId ).append ("-" ).append (_seq ).append (": " );
322344
323345 buf .append (msg );
324346 buf .append ("{ " ).append (getType ());
325- buf .append (", Ver: " ).append (_ver .toString ());
326347 buf .append (", MgmtId: " ).append (_mgmtId ).append (", via: " ).append (_via );
327- buf .append (", Flags: " ).append (Integer .toBinaryString (getFlags ())).append (", " );
328- if (_cmds != null ) {
329- try {
330- s_gogger .toJson (_cmds , buf );
331- } catch (Throwable e ) {
332- s_logger .error ("Gson serialization error on Request.toString() " + getClass ().getCanonicalName (), e );
333- return ;
348+ if (logContent ) {
349+ buf .append (", Ver: " ).append (_ver .toString ());
350+ buf .append (", Flags: " ).append (Integer .toBinaryString (getFlags ())).append (", " );
351+ if (_cmds != null ) {
352+ try {
353+ s_gogger .toJson (_cmds , buf );
354+ } catch (Throwable e ) {
355+ StringBuilder buff = new StringBuilder ();
356+ for (Command cmd : _cmds ) {
357+ buff .append (cmd .getClass ().getName ()).append ("/" );
358+ }
359+ s_logger .error ("Gson serialization error " + buff .toString (), e );
360+ assert false : "More gson errors on " + buff .toString ();
361+ return "" ;
362+ }
363+ } else if (_content != null ) {
364+ buf .append (_content .subSequence (0 , 32 ));
365+ } else {
366+ buf .append ("I've got nada here!" );
367+ assert false : "How can both commands and content be null? What are we sending here?" ;
334368 }
335- } else if (_content != null ) {
336- buf .append (_content .subSequence (0 , 32 ));
337- } else {
338- buf .append ("I've got nada here!" );
339- assert false : "How can both commands and content be null? What are we sending here?" ;
340369 }
341370 buf .append (" }" );
342-
343- s_logger .debug (buf .toString ());
371+ return buf .toString ();
344372 }
345373
346374 /**
@@ -358,7 +386,7 @@ public static Request parse(final byte[] bytes) throws ClassNotFoundException, U
358386 final ByteBuffer buff = ByteBuffer .wrap (bytes );
359387 final byte ver = buff .get ();
360388 final Version version = Version .get (ver );
361- if (version .ordinal () < Version .v3 .ordinal ()) {
389+ if (version .ordinal () != Version .v1 .ordinal ()) {
362390 throw new UnsupportedVersionException ("This version is no longer supported: " + version .toString (), UnsupportedVersionException .IncompatibleVersion );
363391 }
364392 final byte reserved = buff .get (); // tossed away for now.
0 commit comments