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 Transport
acquire()
void
close()
boolean
connect(long timeout)
Connect the transportboolean
disconnect(boolean hard)
Disconnect the transportboolean
disconnect(boolean hard, boolean inUse)
Disconnect the transportprotected abstract void
doConnect()
protected abstract boolean
doDisconnect(boolean hard, boolean inUse)
protected abstract void
doRecv(Response response)
protected abstract void
doSend(Request request)
protected <T extends Response>
longdoSend(Request request, T response, Set<RequestParam> params, long timeout)
protected abstract void
doSkip(Long key)
protected void
finalize()
protected abstract int
getResponseTimeout(Request request)
protected long
getUsageCount()
protected <T extends Response>
booleanhandleIntermediate(Request request, T response)
boolean
isDisconnected()
boolean
isFailed()
protected abstract long
makeKey(Request request)
protected abstract Long
peekKey()
static int
readn(InputStream in, byte[] b, int off, int len)
Read bytes from the input stream into a buffervoid
release()
void
run()
<T extends Response>
Tsendrecv(Request request, T response, Set<RequestParam> params)
Send a request message and recieve responseString
toString()
-
-
-
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:
close
in interfaceAutoCloseable
- See Also:
AutoCloseable.close()
-
release
public void release()
-
finalize
protected void finalize() throws Throwable
- Overrides:
finalize
in 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 TransportException
Connect the transport- Parameters:
timeout
-- Returns:
- whether the transport was connected
- Throws:
TransportException
-
disconnect
public boolean disconnect(boolean hard) throws IOException
Disconnect the transport- Parameters:
hard
-- Returns:
- whether conenction was in use
- Throws:
IOException
-
disconnect
public boolean disconnect(boolean hard, boolean inUse) throws IOException
Disconnect the transport- Parameters:
hard
-inUse
- whether the caller is holding a usage reference on the transport- Returns:
- whether conenction was in use
- Throws:
IOException
-
-