📄 basechannel.java
字号:
return m; } /** * Low level receive * @param b byte array * @exception IOException */ public int getBytes (byte[] b) throws IOException { return serverIn.read (b); } /** * disconnects the TCP/IP session. The instance is ready for * a reconnection. There is no need to create a new ISOChannel<br> * @exception IOException */ public void disconnect () throws IOException { LogEvent evt = new LogEvent (this, "disconnect"); if (serverSocket != null) evt.addMessage ("local port "+serverSocket.getLocalPort() +" remote host "+serverSocket.getInetAddress()); else evt.addMessage (host+":"+port); try { usable = false; setChanged(); notifyObservers(); closeSocket(); if (serverIn != null) { try { serverIn.close(); } catch (IOException ex) { evt.addMessage (ex); } serverIn = null; } if (serverOut != null) { try { serverOut.close(); } catch (IOException ex) { evt.addMessage (ex); } serverOut = null; } } catch (IOException e) { evt.addMessage (e); Logger.log (evt); throw e; } socket = null; } /** * Issues a disconnect followed by a connect * @exception IOException */ public void reconnect() throws IOException { disconnect(); connect(); } public void setLogger (Logger logger, String realm) { this.logger = logger; this.realm = realm; if (originalRealm == null) originalRealm = realm; } public String getRealm () { return realm; } public Logger getLogger() { return logger; } public String getOriginalRealm() { return originalRealm == null ? this.getClass().getName() : originalRealm; } /** * associates this ISOChannel with a name using NameRegistrar * @param name name to register * @see NameRegistrar */ public void setName (String name) { this.name = name; NameRegistrar.register ("channel."+name, this); } /** * @return this ISOChannel's name ("" if no name was set) */ public String getName() { return this.name; } /** * @param filter filter to add * @param direction ISOMsg.INCOMING, ISOMsg.OUTGOING, 0 for both */ public void addFilter (ISOFilter filter, int direction) { switch (direction) { case ISOMsg.INCOMING : incomingFilters.add (filter); break; case ISOMsg.OUTGOING : outgoingFilters.add (filter); break; case 0 : incomingFilters.add (filter); outgoingFilters.add (filter); break; } } /** * @param filter incoming filter to add */ public void addIncomingFilter (ISOFilter filter) { addFilter (filter, ISOMsg.INCOMING); } /** * @param filter outgoing filter to add */ public void addOutgoingFilter (ISOFilter filter) { addFilter (filter, ISOMsg.OUTGOING); } /** * @param filter filter to add (both directions, incoming/outgoing) */ public void addFilter (ISOFilter filter) { addFilter (filter, 0); } /** * @param filter filter to remove * @param direction ISOMsg.INCOMING, ISOMsg.OUTGOING, 0 for both */ public void removeFilter (ISOFilter filter, int direction) { switch (direction) { case ISOMsg.INCOMING : incomingFilters.remove (filter); break; case ISOMsg.OUTGOING : outgoingFilters.remove (filter); break; case 0 : incomingFilters.remove (filter); outgoingFilters.remove (filter); break; } } /** * @param filter filter to remove (both directions) */ public void removeFilter (ISOFilter filter) { removeFilter (filter, 0); } /** * @param filter incoming filter to remove */ public void removeIncomingFilter (ISOFilter filter) { removeFilter (filter, ISOMsg.INCOMING); } /** * @param filter outgoing filter to remove */ public void removeOutgoingFilter (ISOFilter filter) { removeFilter (filter, ISOMsg.OUTGOING); } protected ISOMsg applyOutgoingFilters (ISOMsg m, LogEvent evt) throws VetoException { Iterator iter = outgoingFilters.iterator(); while (iter.hasNext()) m = ((ISOFilter) iter.next()).filter (this, m, evt); return m; } protected ISOMsg applyIncomingFilters (ISOMsg m, LogEvent evt) throws VetoException { return applyIncomingFilters (m, null, null, evt); } protected ISOMsg applyIncomingFilters (ISOMsg m, byte[] header, byte[] image, LogEvent evt) throws VetoException { Iterator iter = incomingFilters.iterator(); while (iter.hasNext()) { ISOFilter f = (ISOFilter) iter.next (); if (image != null && (f instanceof RawIncomingFilter)) m = ((RawIncomingFilter)f).filter (this, m, header, image, evt); else m = f.filter (this, m, evt); } return m; } protected void unpack (ISOMsg m, byte[] b) throws ISOException { m.unpack (b); } /** * Implements Configurable<br> * Properties:<br> * <ul> * <li>host - destination host (if ClientChannel) * <li>port - port number (if ClientChannel) * <li>local-iface - local interfase to use (if ClientChannel) * <li>local-port - local port to bind (if ClientChannel) * </ul> * (host not present indicates a ServerChannel) * * @param cfg Configuration * @throws ConfigurationException */ public void setConfiguration (Configuration cfg) throws ConfigurationException { this.cfg = cfg; String h = cfg.get ("host"); int port = cfg.getInt ("port"); maxPacketLength = cfg.getInt ("max-packet-length", 100000); if (h != null && h.length() > 0) { if (port == 0) throw new ConfigurationException ("invalid port for host '"+h+"'"); setHost (h, port); setLocalAddress (cfg.get("local-iface", null),cfg.getInt("local-port")); String[] altHosts = cfg.getAll ("alternate-host"); int[] altPorts = cfg.getInts ("alternate-port"); hosts = new String[altHosts.length + 1]; ports = new int[altPorts.length + 1]; if (hosts.length != ports.length) { throw new ConfigurationException ( "alternate host/port misconfiguration" ); } hosts[0] = host; ports[0] = port; System.arraycopy (altHosts, 0, hosts, 1, altHosts.length); System.arraycopy (altPorts, 0, ports, 1, altPorts.length); } setOverrideHeader(cfg.getBoolean ("override-header", false)); keepAlive = cfg.getBoolean ("keep-alive", false); if (socketFactory != this && socketFactory instanceof Configurable) ((Configurable)socketFactory).setConfiguration (cfg); try { setTimeout (cfg.getInt ("timeout")); connectTimeout = cfg.getInt ("connect-timeout", timeout); } catch (SocketException e) { throw new ConfigurationException (e); } } public Configuration getConfiguration() { return cfg; } public Collection getIncomingFilters() { return incomingFilters; } public Collection getOutgoingFilters() { return outgoingFilters; } public void setIncomingFilters (Collection filters) { incomingFilters = new Vector (filters); } public void setOutgoingFilters (Collection filters) { outgoingFilters = new Vector (filters); } public void setHeader (byte[] header) { this.header = header; } public void setHeader (String header) { setHeader (header.getBytes()); } public byte[] getHeader () { return header; } public void setOverrideHeader (boolean overrideHeader) { this.overrideHeader = overrideHeader; } public boolean isOverrideHeader () { return overrideHeader; } /** * @return ISOChannel instance with given name. * @throws NameRegistrar.NotFoundException; * @see NameRegistrar */ public static ISOChannel getChannel (String name) throws NameRegistrar.NotFoundException { return (ISOChannel) NameRegistrar.get ("channel."+name); } /** * Gets the ISOClientSocketFactory (may be null) * @see ISOClientSocketFactory * @since 1.3.3 */ public ISOClientSocketFactory getSocketFactory() { return socketFactory; } /** * Sets the specified Socket Factory to create sockets * @param socketFactory the ISOClientSocketFactory * @see ISOClientSocketFactory * @since 1.3.3 */ public void setSocketFactory(ISOClientSocketFactory socketFactory) { this.socketFactory = socketFactory; } public int getMaxPacketLength() { return maxPacketLength; } public void setMaxPacketLength(int maxPacketLength) { this.maxPacketLength = maxPacketLength; } private void closeSocket() throws IOException { if (socket != null) { try { socket.setSoLinger (true, 0); } catch (SocketException e) { // safe to ignore - can be closed already // e.printStackTrace(); } socket.close (); socket = null; } } public Object clone(){ try { BaseChannel channel = (BaseChannel)super.clone(); channel.cnt = (int[])cnt.clone(); return channel; } catch (CloneNotSupportedException e) { throw new InternalError(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -