001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.iso;
020
021import java.io.IOException;
022
023/**
024 * allows the transmision and reception of ISO 8583 Messages
025 *
026 * @author <a href="mailto:apr@cs.com.uy">Alejandro P. Revilla</a>
027 * @author <a href="mailto:alwynschoeman@yahoo.com">Alwyn Schoeman</a>
028 * @version $Revision$ $Date$
029 */
030public interface ISOChannel extends ISOSource {
031    /** Counter index for connection events. */
032    int CONNECT      = 0;
033    /** Counter index for transmitted messages. */
034    int TX           = 1;
035    /** Counter index for received messages. */
036    int RX           = 2;
037    /** Number of counters maintained by this channel. */
038    int SIZEOF_CNT   = 3;
039
040    /**
041     * Associate a packager with this channel
042     * @param p     an ISOPackager
043     */
044    void setPackager(ISOPackager p);
045
046    /**
047     * Connects ISOChannel 
048     * @exception IOException on I/O failure
049     */
050    void connect() throws IOException;
051
052    /**
053     * disconnects ISOChannel
054     * @exception IOException on I/O failure
055     */
056    void disconnect() throws IOException;
057
058    /**
059     * Reconnect channel
060     * @exception IOException on I/O failure
061     */
062    void reconnect() throws IOException;
063
064    /**
065     * @return true if Channel is connected and usable
066     */
067    boolean isConnected();
068
069    /**
070     * Receives an ISOMsg
071     * @return the Message received
072     * @exception IOException on I/O failure
073     * @exception ISOException on ISO packing/unpacking failure
074     */
075    ISOMsg receive() throws IOException, ISOException;
076
077    /**
078     * sends an ISOMsg over the TCP/IP session
079     * @param m the Message to be sent
080     * @exception IOException on I/O failure
081     * @exception ISOException on ISO packing/unpacking failure
082     */
083    void send(ISOMsg m) throws IOException, ISOException;
084    
085    /**
086     * sends a byte[] over the TCP/IP session
087     * @param b the byte array to be sent
088     * @exception IOException on I/O failure
089     * @exception ISOException on ISO packing/unpacking failure
090     */
091    void send(byte[] b) throws IOException, ISOException;
092
093    /**
094     * Marks this channel as usable or not; a non-usable channel will not accept messages.
095     * @param b - usable state
096     */
097    void setUsable(boolean b);
098
099    /**
100     * associates this ISOChannel with a name on NameRegistrar
101     * @param name name to register
102     * @see org.jpos.util.NameRegistrar
103     */
104    void setName(String name);
105
106   /**
107    * Returns this channel's registered name.
108    * @return this ISOChannel's name ("" if no name was set)
109    */
110   String getName();
111
112   /**
113    * Returns the packager used to pack/unpack ISO messages on this channel.
114    * @return current packager
115    */
116   ISOPackager getPackager();
117
118   /**
119    * Returns a clone of this channel.
120    * @return a deep copy of this ISOChannel
121    */
122   Object clone();
123    
124}
125