public abstract class BaseChannel extends java.util.Observable implements FilteredChannel, ClientChannel, ServerChannel, FactoryChannel, LogSource, Configurable, BaseChannelMBean, java.lang.Cloneable, ExceptionHandlerAware
This class is not thread-safe.
ISOChannel is Observable in order to support GUI components
such as ISOChannelPanel.
It now support the new Logger architecture so we will
probably setup ISOChannelPanel to be a LogListener instead
of being an Observer in future releases.
ISOMsg
,
MUX
,
ISOException
,
CSChannel
,
Logger
Modifier and Type | Field and Description |
---|---|
protected int[] |
cnt |
protected byte[] |
header |
protected java.util.List<ISOFilter> |
incomingFilters |
protected Logger |
logger |
protected java.lang.String |
originalRealm |
protected java.util.List<ISOFilter> |
outgoingFilters |
protected boolean |
overrideHeader |
protected ISOPackager |
packager |
protected java.lang.String |
realm |
protected java.io.DataInputStream |
serverIn |
protected java.lang.Object |
serverInLock |
protected java.io.DataOutputStream |
serverOut |
protected java.lang.Object |
serverOutLock |
protected java.net.ServerSocket |
serverSocket |
protected ISOClientSocketFactory |
socketFactory |
protected boolean |
usable |
CONNECT, RX, SIZEOF_CNT, TX
Constructor and Description |
---|
BaseChannel()
constructor shared by server and client
ISOChannels (which have different signatures)
|
BaseChannel(ISOPackager p)
constructs a server ISOChannel
|
BaseChannel(ISOPackager p,
java.net.ServerSocket serverSocket)
constructs a server ISOChannel associated with a Server Socket
|
BaseChannel(java.lang.String host,
int port,
ISOPackager p)
constructs a client ISOChannel
|
Modifier and Type | Method and Description |
---|---|
void |
accept(java.net.ServerSocket s)
Accepts connection
|
void |
addFilter(ISOFilter filter) |
void |
addFilter(ISOFilter filter,
int direction) |
void |
addIncomingFilter(ISOFilter filter) |
void |
addOutgoingFilter(ISOFilter filter) |
protected ISOMsg |
applyIncomingFilters(ISOMsg m,
byte[] header,
byte[] image,
LogEvent evt) |
protected ISOMsg |
applyIncomingFilters(ISOMsg m,
LogEvent evt) |
protected ISOMsg |
applyOutgoingFilters(ISOMsg m,
LogEvent evt) |
protected void |
applyTimeout()
sets timeout, and also keep alive
|
java.lang.Object |
clone()
Expose channel clonning interface
|
protected void |
closeSocket() |
void |
connect()
Connects client ISOChannel to server
|
protected void |
connect(java.net.Socket socket)
setup I/O Streams from socket
|
protected ISOMsg |
createISOMsg() |
protected ISOMsg |
createMsg()
support old factory method name for backward compatibility
|
void |
disconnect()
disconnects the TCP/IP session.
|
int |
getBytes(byte[] b)
Low level receive
|
static ISOChannel |
getChannel(java.lang.String name) |
Configuration |
getConfiguration() |
int[] |
getCounters() |
protected ISOHeader |
getDynamicHeader(byte[] image)
Allow subclasses to override the Default header on
incoming messages.
|
protected ISOPackager |
getDynamicPackager(byte[] image)
allow subclasses to override default packager
on incoming messages
|
protected ISOPackager |
getDynamicPackager(byte[] header,
byte[] image)
allow subclasses to override default packager
on incoming messages
|
protected ISOPackager |
getDynamicPackager(ISOMsg m)
allow subclasses to override default packager
on outgoing messages
|
java.util.Map<java.lang.Class<? extends java.lang.Exception>,java.util.List<ExceptionHandler>> |
getExceptionHandlers() |
byte[] |
getHeader() |
protected int |
getHeaderLength() |
protected int |
getHeaderLength(byte[] b) |
protected int |
getHeaderLength(ISOMsg m) |
java.lang.String |
getHost() |
java.util.Collection<ISOFilter> |
getIncomingFilters() |
Logger |
getLogger() |
int |
getMaxPacketLength() |
protected void |
getMessage(byte[] b,
int offset,
int len) |
protected int |
getMessageLength() |
protected void |
getMessageTrailer(ISOMsg m)
Read some trailer data from this channel and optionally store it in the incoming ISOMsg.
|
protected void |
getMessageTrailler()
Deprecated.
use getMessageTrailer(ISOMsg m) instead.
|
java.lang.String |
getName() |
java.lang.String |
getOriginalRealm() |
java.util.Collection<ISOFilter> |
getOutgoingFilters() |
ISOPackager |
getPackager() |
int |
getPort() |
java.lang.String |
getRealm() |
java.net.ServerSocket |
getServerSocket() |
java.net.Socket |
getSocket() |
ISOClientSocketFactory |
getSocketFactory()
Gets the ISOClientSocketFactory (may be null)
|
int |
getSoLingerSeconds() |
int |
getTimeout() |
boolean |
isConnected() |
boolean |
isExpectKeepAlive() |
boolean |
isOverrideHeader() |
protected boolean |
isRejected(byte[] b) |
boolean |
isSoLingerOn() |
protected java.net.Socket |
newSocket(java.lang.String[] hosts,
int[] ports,
LogEvent evt) |
protected java.net.Socket |
newSocket(java.lang.String host,
int port)
factory method pattern (as suggested by Vincent.Greene@amo.com)
|
protected byte[] |
pack(ISOMsg m) |
protected void |
postConnectHook() |
protected byte[] |
readHeader(int hLen)
Reads in a message header.
|
ISOMsg |
receive()
Waits and receive an ISOMsg over the TCP/IP session
|
void |
reconnect()
Issues a disconnect followed by a connect
|
void |
removeFilter(ISOFilter filter) |
void |
removeFilter(ISOFilter filter,
int direction) |
void |
removeIncomingFilter(ISOFilter filter) |
void |
removeOutgoingFilter(ISOFilter filter) |
void |
resetCounters()
reset stat info
|
void |
send(byte[] b)
sends a byte[] over the TCP/IP session
|
void |
send(ISOMsg m)
sends an ISOMsg over the TCP/IP session
|
void |
sendKeepAlive()
Sends a high-level keep-alive message (zero length)
|
protected void |
sendMessage(byte[] b,
int offset,
int len) |
protected void |
sendMessageHeader(ISOMsg m,
int len) |
protected void |
sendMessageLength(int len) |
protected void |
sendMessageTrailer(ISOMsg m,
byte[] b)
Send a Message trailer.
|
protected void |
sendMessageTrailler(ISOMsg m,
byte[] b)
Deprecated.
use sendMessageTrailer(ISOMsg m, byte[] b instead.
|
protected void |
sendMessageTrailler(ISOMsg m,
int len)
Deprecated.
use sendMessageTrailer(ISOMsg m, byte[] b) instead.
|
void |
setConfiguration(Configuration cfg)
Implements Configurable
Properties: host - destination host (if ClientChannel) port - port number (if ClientChannel) local-iface - local interfase to use (if ClientChannel) local-port - local port to bind (if ClientChannel) (host not present indicates a ServerChannel) |
void |
setHeader(byte[] header) |
void |
setHeader(java.lang.String header) |
void |
setHost(java.lang.String host) |
void |
setHost(java.lang.String host,
int port)
initialize an ISOChannel
|
void |
setIncomingFilters(java.util.Collection filters) |
void |
setLocalAddress(java.lang.String iface,
int port)
initialize an ISOChannel
|
void |
setLogger(Logger logger,
java.lang.String realm) |
void |
setMaxPacketLength(int maxPacketLength) |
void |
setName(java.lang.String name)
associates this ISOChannel with a name using NameRegistrar
|
void |
setOutgoingFilters(java.util.Collection filters) |
void |
setOverrideHeader(boolean overrideHeader) |
void |
setPackager(ISOPackager p)
set Packager for channel
|
void |
setPort(int port) |
void |
setServerSocket(java.net.ServerSocket sock)
Associates this ISOChannel with a server socket
|
void |
setSocketFactory(ISOClientSocketFactory socketFactory)
Sets the specified Socket Factory to create sockets
|
void |
setSoLinger(boolean on,
int linger)
Socket SO_LINGER option to use when closing the socket.
|
void |
setTimeout(int timeout)
sets socket timeout (as suggested by
Leonard Thomas
|
void |
setUsable(boolean b) |
protected boolean |
shouldIgnore(byte[] b) |
protected byte[] |
streamReceive() |
protected void |
unpack(ISOMsg m,
byte[] b) |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addHandler, addHandler, handle, removeHandler, removeHandler, removeHandlers
protected boolean usable
protected boolean overrideHeader
protected java.io.DataInputStream serverIn
protected java.io.DataOutputStream serverOut
protected java.lang.Object serverInLock
protected java.lang.Object serverOutLock
protected ISOPackager packager
protected java.net.ServerSocket serverSocket
protected java.util.List<ISOFilter> incomingFilters
protected java.util.List<ISOFilter> outgoingFilters
protected ISOClientSocketFactory socketFactory
protected int[] cnt
protected Logger logger
protected java.lang.String realm
protected java.lang.String originalRealm
protected byte[] header
public BaseChannel()
public BaseChannel(java.lang.String host, int port, ISOPackager p)
host
- server TCP Addressport
- server port numberp
- an ISOPackagerISOPackager
public BaseChannel(ISOPackager p) throws java.io.IOException
p
- an ISOPackagerjava.io.IOException
- on errorISOPackager
public BaseChannel(ISOPackager p, java.net.ServerSocket serverSocket) throws java.io.IOException
p
- an ISOPackagerserverSocket
- where to accept a connectionjava.io.IOException
- on errorISOPackager
public void setHost(java.lang.String host, int port)
setHost
in interface ClientChannel
host
- server TCP Addressport
- server port numberpublic void setLocalAddress(java.lang.String iface, int port)
iface
- server TCP Addressport
- server port numberpublic void setHost(java.lang.String host)
setHost
in interface BaseChannelMBean
host
- to connect (client ISOChannel)public void setPort(int port)
setPort
in interface BaseChannelMBean
port
- to connect (client ISOChannel)public java.lang.String getHost()
getHost
in interface BaseChannelMBean
getHost
in interface ClientChannel
public int getPort()
getPort
in interface BaseChannelMBean
getPort
in interface ClientChannel
public void setPackager(ISOPackager p)
setPackager
in interface ISOChannel
p
- an ISOPackagerISOPackager
public ISOPackager getPackager()
getPackager
in interface ISOChannel
public void setServerSocket(java.net.ServerSocket sock)
sock
- where to accept a connectionpublic java.util.Map<java.lang.Class<? extends java.lang.Exception>,java.util.List<ExceptionHandler>> getExceptionHandlers()
getExceptionHandlers
in interface ExceptionHandlerAware
public void resetCounters()
public int[] getCounters()
public boolean isConnected()
isConnected
in interface BaseChannelMBean
isConnected
in interface ISOChannel
isConnected
in interface ISOSource
protected void connect(java.net.Socket socket) throws java.io.IOException
socket
- a Socket (client or server)java.io.IOException
- on errorprotected void postConnectHook() throws java.io.IOException
java.io.IOException
protected java.net.Socket newSocket(java.lang.String host, int port) throws java.io.IOException
host
- remote hostport
- remote portjava.io.IOException
- on error
Use Socket factory if exists. If it is missing create a normal socketISOClientSocketFactory
protected java.net.Socket newSocket(java.lang.String[] hosts, int[] ports, LogEvent evt) throws java.io.IOException
java.io.IOException
public java.net.Socket getSocket()
public java.net.ServerSocket getServerSocket()
public void setTimeout(int timeout) throws java.net.SocketException
timeout
- in millisecondsjava.net.SocketException
- on errorpublic int getTimeout()
protected void applyTimeout() throws java.net.SocketException
java.net.SocketException
public void setSoLinger(boolean on, int linger)
Socket.setSoLinger(boolean, int)
public boolean isSoLingerOn()
public int getSoLingerSeconds()
public void connect() throws java.io.IOException
connect
in interface BaseChannelMBean
connect
in interface ISOChannel
java.io.IOException
public void accept(java.net.ServerSocket s) throws java.io.IOException
accept
in interface ServerChannel
java.io.IOException
public void setUsable(boolean b)
setUsable
in interface ISOChannel
b
- - new Usable state (used by ISOMUX internals to
flag as unusable in order to force a reconnection)protected ISOPackager getDynamicPackager(ISOMsg m)
m
- outgoing ISOMsgprotected ISOPackager getDynamicPackager(byte[] image)
image
- incoming message imageprotected ISOPackager getDynamicPackager(byte[] header, byte[] image)
header
- message headerimage
- incoming message imageprotected ISOHeader getDynamicHeader(byte[] image)
image
- message imageprotected void sendMessageLength(int len) throws java.io.IOException
java.io.IOException
protected void sendMessageHeader(ISOMsg m, int len) throws java.io.IOException
java.io.IOException
protected void sendMessageTrailler(ISOMsg m, int len) throws java.io.IOException
m
- a reference to the ISOMsglen
- the packed image lengthjava.io.IOException
- on errorprotected void sendMessageTrailler(ISOMsg m, byte[] b) throws java.io.IOException
java.io.IOException
protected void sendMessageTrailer(ISOMsg m, byte[] b) throws java.io.IOException
m
- The unpacked ISOMsg.b
- The packed ISOMsg image.java.io.IOException
protected void getMessageTrailler() throws java.io.IOException
java.io.IOException
protected void getMessageTrailer(ISOMsg m) throws java.io.IOException
m
- The ISOMessage to store the trailer data.java.io.IOException
ISOMsg.setTrailer(byte[]).
protected void getMessage(byte[] b, int offset, int len) throws java.io.IOException, ISOException
java.io.IOException
ISOException
protected int getMessageLength() throws java.io.IOException, ISOException
java.io.IOException
ISOException
protected int getHeaderLength()
protected int getHeaderLength(byte[] b)
protected int getHeaderLength(ISOMsg m)
protected byte[] streamReceive() throws java.io.IOException
java.io.IOException
protected void sendMessage(byte[] b, int offset, int len) throws java.io.IOException
java.io.IOException
public void send(ISOMsg m) throws java.io.IOException, ISOException
send
in interface ISOChannel
send
in interface ISOSource
m
- the Message to be sentjava.io.IOException
ISOException
ISOFilter.VetoException;
public void send(byte[] b) throws java.io.IOException, ISOException
send
in interface ISOChannel
b
- the byte array to be sentjava.io.IOException
ISOException
ISOFilter.VetoException;
public void sendKeepAlive() throws java.io.IOException
java.io.IOException
- on exceptionpublic boolean isExpectKeepAlive()
protected boolean isRejected(byte[] b)
protected boolean shouldIgnore(byte[] b)
protected ISOMsg createMsg()
protected ISOMsg createISOMsg()
protected byte[] readHeader(int hLen) throws java.io.IOException
hLen
- The Length og the reader to readjava.io.IOException
- on errorpublic ISOMsg receive() throws java.io.IOException, ISOException
receive
in interface ISOChannel
java.io.IOException
ISOException
public int getBytes(byte[] b) throws java.io.IOException
b
- byte arrayjava.io.IOException
- on errorpublic void disconnect() throws java.io.IOException
disconnect
in interface BaseChannelMBean
disconnect
in interface ISOChannel
java.io.IOException
public void reconnect() throws java.io.IOException
reconnect
in interface BaseChannelMBean
reconnect
in interface ISOChannel
java.io.IOException
public void setLogger(Logger logger, java.lang.String realm)
public java.lang.String getOriginalRealm()
public void setName(java.lang.String name)
setName
in interface ISOChannel
name
- name to registerNameRegistrar
public java.lang.String getName()
getName
in interface ISOChannel
public void addFilter(ISOFilter filter, int direction)
filter
- filter to adddirection
- ISOMsg.INCOMING, ISOMsg.OUTGOING, 0 for bothpublic void addIncomingFilter(ISOFilter filter)
addIncomingFilter
in interface FilteredChannel
filter
- incoming filter to addpublic void addOutgoingFilter(ISOFilter filter)
addOutgoingFilter
in interface FilteredChannel
filter
- outgoing filter to addpublic void addFilter(ISOFilter filter)
addFilter
in interface FilteredChannel
filter
- filter to add (both directions, incoming/outgoing)public void removeFilter(ISOFilter filter, int direction)
filter
- filter to removedirection
- ISOMsg.INCOMING, ISOMsg.OUTGOING, 0 for bothpublic void removeFilter(ISOFilter filter)
removeFilter
in interface FilteredChannel
filter
- filter to remove (both directions)public void removeIncomingFilter(ISOFilter filter)
removeIncomingFilter
in interface FilteredChannel
filter
- incoming filter to removepublic void removeOutgoingFilter(ISOFilter filter)
removeOutgoingFilter
in interface FilteredChannel
filter
- outgoing filter to removeprotected ISOMsg applyOutgoingFilters(ISOMsg m, LogEvent evt) throws ISOFilter.VetoException
ISOFilter.VetoException
protected ISOMsg applyIncomingFilters(ISOMsg m, LogEvent evt) throws ISOFilter.VetoException
ISOFilter.VetoException
protected ISOMsg applyIncomingFilters(ISOMsg m, byte[] header, byte[] image, LogEvent evt) throws ISOFilter.VetoException
ISOFilter.VetoException
protected void unpack(ISOMsg m, byte[] b) throws ISOException
ISOException
protected byte[] pack(ISOMsg m) throws ISOException
ISOException
public void setConfiguration(Configuration cfg) throws ConfigurationException
setConfiguration
in interface Configurable
cfg
- ConfigurationConfigurationException
public Configuration getConfiguration()
public java.util.Collection<ISOFilter> getIncomingFilters()
getIncomingFilters
in interface FilteredChannel
public java.util.Collection<ISOFilter> getOutgoingFilters()
getOutgoingFilters
in interface FilteredChannel
public void setIncomingFilters(java.util.Collection filters)
setIncomingFilters
in interface FilteredChannel
filters
- incoming filter setpublic void setOutgoingFilters(java.util.Collection filters)
setOutgoingFilters
in interface FilteredChannel
filters
- outgoing filter setpublic void setHeader(byte[] header)
public void setHeader(java.lang.String header)
public byte[] getHeader()
public void setOverrideHeader(boolean overrideHeader)
public boolean isOverrideHeader()
public static ISOChannel getChannel(java.lang.String name) throws NameRegistrar.NotFoundException
name
- the Channel's name (without the "channel." prefix)NameRegistrar.NotFoundException;
NameRegistrar.NotFoundException
NameRegistrar
public ISOClientSocketFactory getSocketFactory()
ISOClientSocketFactory
public void setSocketFactory(ISOClientSocketFactory socketFactory)
setSocketFactory
in interface FactoryChannel
socketFactory
- the ISOClientSocketFactoryISOClientSocketFactory
public int getMaxPacketLength()
public void setMaxPacketLength(int maxPacketLength)
protected void closeSocket() throws java.io.IOException
java.io.IOException
public java.lang.Object clone()
ISOChannel
clone
in interface ISOChannel
clone
in class java.lang.Object