📄 safchannel.java
字号:
/* * Copyright (c) 2000 jPOS.org. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the jPOS project * (http://www.jpos.org/)". Alternately, this acknowledgment may * appear in the software itself, if and wherever such third-party * acknowledgments normally appear. * * 4. The names "jPOS" and "jPOS.org" must not be used to endorse * or promote products derived from this software without prior * written permission. For written permission, please contact * license@jpos.org. * * 5. Products derived from this software may not be called "jPOS", * nor may "jPOS" appear in their name, without prior written * permission of the jPOS project. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE JPOS PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the jPOS Project. For more * information please see <http://www.jpos.org/>. */package org.jpos.iso.channel;import java.io.IOException;import java.io.Serializable;import java.io.OutputStream;import java.io.ObjectOutputStream;import java.io.InputStream;import java.io.ObjectInputStream;import java.io.File;import java.io.FileOutputStream;import java.io.PrintStream;import java.util.Date;import java.util.Vector;import java.util.Collection;import java.util.Iterator;import java.util.LinkedList;import org.jpos.iso.ISOMsg;import org.jpos.iso.ISOField;import org.jpos.iso.ISODate;import org.jpos.iso.ISOUtil;import org.jpos.iso.ISORequest;import org.jpos.iso.ISOChannel;import org.jpos.iso.ISOPackager;import org.jpos.iso.ISOException;import org.jpos.iso.FilteredChannel;import org.jpos.iso.ISOMUX;import org.jpos.core.Sequencer;import org.jpos.core.VolatileSequencer;import org.jpos.util.NameRegistrar;import org.jpos.util.BlockingQueue;import org.jpos.util.Logger;import org.jpos.util.LogEvent;import org.jpos.util.LogSource;import org.jpos.util.Loggeable;import org.jpos.core.Configuration;import org.jpos.core.ConfigurationException;import org.jpos.core.ReConfigurable;import org.jpos.iso.ISOFilter;import org.jpos.iso.ISOFilter.VetoException;import com.sun.jini.reliableLog.ReliableLog;import com.sun.jini.reliableLog.LogException;import com.sun.jini.reliableLog.LogHandler;/** * Store & Forward channel * Incoming filters are processed at 'store' time while Outgoing * filters are processed at 'forward' time. * * @author <a href="mailto:apr@cs.com.uy">Alejandro P. Revilla</a> * @version $Revision: 1.6 $ $Date: 2002/01/26 20:41:48 $ * @since 1.3.9 * @see FilteredChannel */public class SAFChannel extends LogHandler implements ISOChannel, LogSource, ReConfigurable, Runnable, SAFChannelMBean, FilteredChannel{ boolean usable = false; private int[] cnt; String name; BlockingQueue queue; Logger logger; String realm; Configuration cfg; ReliableLog log; ISOMUX mux; boolean debug = false; Vector outgoingFilters, incomingFilters; public SAFChannel () { super(); cnt = new int[SIZEOF_CNT]; queue = new BlockingQueue(); outgoingFilters = new Vector(); incomingFilters = new Vector(); new Thread (this).start (); } public void setPackager(ISOPackager packager) { } public void connect () { } public void disconnect () { } public void reconnect () { } public boolean isConnected() { return usable; } public synchronized void send (ISOMsg m) throws IOException,ISOException, VetoException { if (!isConnected()) throw new ISOException ("unconnected ISOChannel retry later"); m.setDirection(ISOMsg.INCOMING); LogEvent evt = new LogEvent (this, "saf-send", m); m = applyFilters (outgoingFilters, m, evt); m.setDirection(ISOMsg.INCOMING); logUpdate (new LogEntry (LogEntry.QUEUE, m)); queue.enqueue (m); cnt[TX]++; Logger.log (evt); } /* --------------------------------------------------------------- Future expansion, we may want to store messages in an external file, should our in-memory queue grows beyond a high water mark private void addMessage (String f, ISOMsg m) throws IOException { FileOutputStream fos = new FileOutputStream (f, true); ObjectOutputStream out = new ObjectOutputStream (fos); out.writeObject (m); out.flush(); fos.getFD().sync(); out.close(); } ---------------------------------------------------------------- */ public ISOMsg receive() throws ISOException { throw new ISOException ("can not receive from SAFChannel"); } public void setUsable (boolean usable) { this.usable = usable; } public void setName (String name) { this.name = name; NameRegistrar.register ("channel."+name, this); } public String getName() { return name; } public ISOPackager getPackager() { return null; } public void resetCounters() { cnt = new int[SIZEOF_CNT]; } public void setLogger (Logger logger, String realm) { this.logger = logger; this.realm = realm; } public String getRealm () { return realm; } public Logger getLogger() { return logger; } /** * @param cfg * <ul> * <li>logdir - reliable log directory * <li>flag-retransmissions - ditto (i.e. sends 0221 instead of 0220) * <li>destination-mux - ditto * <li>timeout - time in millis to wait for a response * <li>delay - inter-message delay * <li>debug - true/false * </ul> */ public void setConfiguration (Configuration cfg) throws ConfigurationException { debug = cfg.getBoolean ("debug") && (getLogger() != null); if (this.cfg == null) { try { ReliableLog log = new ReliableLog (cfg.get("logdir",null), this); try { log.recover(); } catch (LogException le) { Logger.log (new LogEvent (this, "recover", le)); } log.snapshot(); setReliableLog (log); if (debug) dumpList (); setUsable (true); } catch (IOException e) { throw new ConfigurationException (e); } } this.cfg = cfg; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -