1 20 21 22 23 package org.snmp4j.transport; 24 25 import org.snmp4j.TransportMapping; 26 import org.snmp4j.MessageDispatcher; 27 import java.io.IOException ; 28 import org.snmp4j.smi.Address; 29 import java.util.Vector ; 30 import java.nio.ByteBuffer ; 31 32 40 public abstract class AbstractTransportMapping implements TransportMapping { 41 42 protected Vector transportListener = new Vector (1); 43 protected int maxInboundMessageSize = (1 << 16) - 1; 44 protected boolean asyncMsgProcessingSupported = true; 45 46 public abstract Class getSupportedAddressClass(); 47 48 public abstract void sendMessage(Address address, byte[] message) 49 throws IOException ; 50 51 public void addMessageDispatcher(MessageDispatcher dispatcher) { 52 addTransportListener(dispatcher); 53 } 54 55 public void removeMessageDispatcher(MessageDispatcher dispatcher) { 56 removeTransportListener(dispatcher); 57 } 58 59 public synchronized void addTransportListener(TransportListener l) { 60 Vector v = (transportListener == null) ? 61 new Vector (2) : (Vector ) transportListener.clone(); 62 if (!v.contains(l)) { 63 v.addElement(l); 64 transportListener = v; 65 } 66 } 67 68 public synchronized void removeTransportListener(TransportListener l) { 69 if (transportListener != null && transportListener.contains(l)) { 70 Vector v = (Vector ) transportListener.clone(); 71 v.removeElement(l); 72 transportListener = v; 73 } 74 } 75 76 protected void fireProcessMessage(Address address, ByteBuffer buf) { 77 if (transportListener != null) { 78 for (int i=0; i<transportListener.size(); i++) { 79 TransportListener l; 80 synchronized (this) { 81 l = (TransportListener) transportListener.get(i); 82 } 83 l.processMessage(this, address, buf); 84 } 85 } 86 } 87 88 89 public abstract void close() throws IOException ; 90 public abstract void listen() throws IOException ; 91 92 public int getMaxInboundMessageSize() { 93 return maxInboundMessageSize; 94 } 95 96 105 public boolean isAsyncMsgProcessingSupported() { 106 return asyncMsgProcessingSupported; 107 } 108 109 121 public void setAsyncMsgProcessingSupported( 122 boolean asyncMsgProcessingSupported) { 123 this.asyncMsgProcessingSupported = asyncMsgProcessingSupported; 124 } 125 126 } 127 | Popular Tags |