1 /* 2 Copyright 2007 Ramon Servadei 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package fulmine.event.system; 17 18 import static fulmine.util.Utils.string; 19 20 import java.util.Arrays; 21 22 import fulmine.event.AbstractEvent; 23 import fulmine.event.IEventFrameExecution; 24 import fulmine.event.IEventSource; 25 import fulmine.event.listener.IEventListener; 26 import fulmine.model.container.IContainer; 27 28 /** 29 * A transmission event encapsulates the <code>byte[]</code> that holds the 30 * state change in wire form of an {@link IContainer} to transmit. 31 * <p> 32 * This implementation of an {@link ISystemEvent} can be raised by a non- 33 * {@link ISystemEventSource}. This is so that an {@link IEventListener} for an 34 * {@link IContainer} will not receive these events. 35 * 36 * @author Ramon Servadei 37 */ 38 public final class TxEvent extends AbstractEvent implements ISystemEvent 39 { 40 /** The transmit buffer */ 41 private final byte[] buffer; 42 43 /** The time taken in nanoseconds to create the data */ 44 private final long bufferCreateTime; 45 46 /** 47 * Standard constructor 48 * 49 * @param source 50 * the source for this event 51 * @param buffer 52 * the data buffer to transmit 53 * @param frame 54 * the frame that the data buffer was created in 55 * @param drivingFrame 56 * the driving frame of the frame 57 * @param bufferCreateTime 58 * the time taken to create the buffer itself 59 */ 60 public TxEvent(IEventSource source, byte[] buffer, 61 IEventFrameExecution frame, IEventFrameExecution drivingFrame, 62 long bufferCreateTime) 63 { 64 super(); 65 setSource(source); 66 setFrame(frame); 67 setDrivingFrame(drivingFrame); 68 this.buffer = buffer; 69 this.bufferCreateTime = bufferCreateTime; 70 } 71 72 /** 73 * Get the byte[] holding the state in wire form to transmit 74 * 75 * @return a <code>byte[]</code> 76 */ 77 public byte[] getBuffer() 78 { 79 return this.buffer; 80 } 81 82 /** 83 * The time taken to create the data buffer for the event 84 * 85 * @return the time in nanoseconds to create the data buffer 86 */ 87 public long getBufferCreateTime() 88 { 89 return this.bufferCreateTime; 90 } 91 92 /** 93 * Provides a trace string the shows the byte level contents of the data 94 * buffer. Used for fine grain debugging. 95 * 96 * @return a trace string 97 */ 98 public String getTraceString() 99 { 100 return string(this, "buffer=" + Arrays.toString(getBuffer()) 101 + ", source=" + getSource()); 102 } 103 104 protected String getAdditionalToString() 105 { 106 return "buffer=[" + getBuffer().length + " bytes]"; 107 } 108 }