PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/net/SmscLink.java

http://mobicents.googlecode.com/
Java | 120 lines | 14 code | 12 blank | 94 comment | 0 complexity | b280c0dff01afa61efd44d32b792d8a2 MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.mobicents.protocols.smpp.net;
 24
 25import java.io.IOException;
 26
 27import org.mobicents.protocols.smpp.message.SMPPPacket;
 28
 29/**
 30 * Interface for the network link to an SMSC. 
 31 * @version $Id: SmscLink.java 457 2009-01-15 17:37:42Z orank $
 32 */
 33public interface SmscLink {
 34    /**
 35     * Initiate the connection to the SMSC. If this link is already connected,
 36     * this method should do nothing.
 37     * @throws IOException
 38     */
 39    void connect() throws IOException;
 40    
 41    /**
 42     * Disconnect from the SMSC. If this link is already closed,
 43     * this method should do nothing.
 44     * @throws IOException
 45     */
 46    void disconnect() throws IOException;
 47    
 48    /**
 49     * Determine if the underlying link is connected to the SMSC.
 50     * @return <code>true</code> if connected, <code>false</code> otherwise.
 51     */
 52    boolean isConnected();
 53    
 54    /**
 55     * Send an SMPP packet to the SMSC.
 56     * @param packet The packet to send.
 57     * @param withOptionalParams <code>true</code> to send the packet&apos;s
 58     * optional parameters during the write, <code>false</code> to omit the
 59     * optional parameters.
 60     * @throws IOException
 61     */
 62    void write(SMPPPacket packet, boolean withOptionalParams) throws IOException;
 63    
 64    /**
 65     * If the underlying link implements some form of output buffering, then
 66     * this method should flush the buffer. If the link does not do any form
 67     * of buffering, this method should do nothing.
 68     * @throws IOException
 69     */
 70    void flush() throws IOException;
 71    
 72    /**
 73     * Read the next SMPP packet from the underlying link. This method should
 74     * block until it has fully read all of the bytes for the next packet,
 75     * barring any time out. The byte array supplied to the method call will
 76     * be used to store the packet&apos;s bytes, and that same array will be
 77     * returned. However, if the buffer is not large enough to hold the
 78     * packet, a <b>new</b> byte array will be created, the packet stored in it
 79     * and this new array will be returned.
 80     * @param buffer A byte array to use to store the packet data.
 81     * @return <code>buffer</code> will be returned if it is large enough to
 82     * hold all of the packet&apos;s data, otherwise a new array is created
 83     * and returned with the packet data.
 84     * @throws IOException
 85     * @throws ReadTimeoutException
 86     */
 87    SMPPPacket read() throws IOException;
 88    
 89    /**
 90     * Get the current timeout for the underlying link. If read timeouts
 91     * are not supported, calls to this method should throw a
 92     * {@link org.mobicents.protocols.smpp.UnsupportedOperationException}.
 93     * @return The current timeout, specified in milliseconds.
 94     * @throws org.mobicents.protocols.smpp.UnsupportedOperationException If read timeouts
 95     * are not supported.
 96     * @see #setTimeout(int)
 97     */
 98    int getTimeout();
 99
100    /**
101     * Set the read timeout for the underlying link. If a blocked read takes
102     * longer than the specified <code>timeout</code>, then a
103     * {@link ReadTimeoutException} should be thrown. Supporting read timeouts
104     * is optional for SmscLink implementations. If it is not supported,
105     * calls to this method must throw an
106     * {@link org.mobicents.protocols.smpp.UnsupportedOperationException}. A timeout value
107     * of <code>0</code> deactivates timeouts - reads will block forever.
108     * @param timeout The new timeout value, specified in milliseconds.
109     * @throws org.mobicents.protocols.smpp.UnsupportedOperationException If read timeouts
110     * are not supported.
111     */
112    void setTimeout(int timeout);
113    
114    /**
115     * Determine if this SMSC link supports read timeouts.
116     * @return <code>true</code> if the implementation supports read timeouts,
117     * <code>false</code> if not.
118     */
119    boolean isTimeoutSupported();
120}