Package jcifs.util.transport
Class Transport
- java.lang.Object
-
- jcifs.util.transport.Transport
-
- All Implemented Interfaces:
AutoCloseable,Runnable
public abstract class Transport extends Object implements Runnable, AutoCloseable
This class simplifies communication for protocols that support multiplexing requests. It encapsulates a stream and some protocol knowledge (provided by a concrete subclass) so that connecting, disconnecting, sending, and receiving can be syncronized properly. Apparatus is provided to send and receive requests concurrently.
-
-
Constructor Summary
Constructors Constructor Description Transport()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Transportacquire()voidclose()booleanconnect(long timeout)Connect the transportbooleandisconnect(boolean hard)Disconnect the transportbooleandisconnect(boolean hard, boolean inUse)Disconnect the transportprotected abstract voiddoConnect()protected abstract booleandoDisconnect(boolean hard, boolean inUse)protected abstract voiddoRecv(Response response)protected abstract voiddoSend(Request request)protected <T extends Response>
longdoSend(Request request, T response, Set<RequestParam> params, long timeout)protected abstract voiddoSkip(Long key)protected voidfinalize()protected abstract intgetResponseTimeout(Request request)protected longgetUsageCount()protected <T extends Response>
booleanhandleIntermediate(Request request, T response)booleanisDisconnected()booleanisFailed()protected abstract longmakeKey(Request request)protected abstract LongpeekKey()static intreadn(InputStream in, byte[] b, int off, int len)Read bytes from the input stream into a buffervoidrelease()voidrun()<T extends Response>
Tsendrecv(Request request, T response, Set<RequestParam> params)Send a request message and recieve responseStringtoString()
-
-
-
Method Detail
-
readn
public static int readn(InputStream in, byte[] b, int off, int len) throws IOException
Read bytes from the input stream into a buffer- Parameters:
in-b-off-len-- Returns:
- number of bytes read
- Throws:
IOException
-
acquire
public Transport acquire()
- Returns:
- session increased usage count
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- See Also:
AutoCloseable.close()
-
release
public void release()
-
finalize
protected void finalize() throws Throwable- Overrides:
finalizein classObject- Throws:
Throwable- See Also:
Object.finalize()
-
getUsageCount
protected long getUsageCount()
- Returns:
- the number of known usages
-
makeKey
protected abstract long makeKey(Request request) throws IOException
- Throws:
IOException
-
peekKey
protected abstract Long peekKey() throws IOException
- Throws:
IOException
-
doSend
protected abstract void doSend(Request request) throws IOException
- Throws:
IOException
-
doRecv
protected abstract void doRecv(Response response) throws IOException
- Throws:
IOException
-
doSkip
protected abstract void doSkip(Long key) throws IOException
- Throws:
IOException
-
isDisconnected
public boolean isDisconnected()
- Returns:
- whether the transport is disconnected
-
isFailed
public boolean isFailed()
- Returns:
- whether the transport is marked failed
-
sendrecv
public <T extends Response> T sendrecv(Request request, T response, Set<RequestParam> params) throws IOException
Send a request message and recieve response- Parameters:
request-response-params-- Returns:
- the response
- Throws:
IOException
-
doSend
protected <T extends Response> long doSend(Request request, T response, Set<RequestParam> params, long timeout) throws IOException
- Parameters:
request-response-params-timeout-- Returns:
- Throws:
IOException
-
handleIntermediate
protected <T extends Response> boolean handleIntermediate(Request request, T response)
- Parameters:
request-response-- Returns:
-
getResponseTimeout
protected abstract int getResponseTimeout(Request request)
- Parameters:
request-- Returns:
-
doDisconnect
protected abstract boolean doDisconnect(boolean hard, boolean inUse) throws IOException- Throws:
IOException
-
connect
public boolean connect(long timeout) throws TransportExceptionConnect the transport- Parameters:
timeout-- Returns:
- whether the transport was connected
- Throws:
TransportException
-
disconnect
public boolean disconnect(boolean hard) throws IOExceptionDisconnect the transport- Parameters:
hard-- Returns:
- whether conenction was in use
- Throws:
IOException
-
disconnect
public boolean disconnect(boolean hard, boolean inUse) throws IOExceptionDisconnect the transport- Parameters:
hard-inUse- whether the caller is holding a usage reference on the transport- Returns:
- whether conenction was in use
- Throws:
IOException
-
-