|
JXTA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.net.Socket
net.jxta.socket.JxtaSocket
public class JxtaSocket
JxtaSocket is a sub-class of java.net.socket, and should be used like a java.net.Socket. Key differences to keep in mind are the following :
- JxtaSocket does not implement Nagle's algorithm, therefore at end of a data frame a flush must invoked to enure all buffered data is packaged and transmitted. - JxtaSocket does not implement keep-alive, therefore it is possible the underlaying messengers to be closed due to lack of inactivity, which manifests in a short latency, while the messenger are recreated. This limitation should cease to exist as soon the inactivity logic is removed.
Field Summary | |
---|---|
protected boolean |
bound
If true then we believer our end of the connection is open. |
protected boolean |
closed
If true then this socket has been closed and can no longer be used. |
protected Object |
closeLock
Lock for closing states. |
protected boolean |
connected
If true then we believe the remote peer currently has this socket open. |
protected OutputPipe |
connectOutpipe
Used to negotiate connection parameters |
protected PeerGroup |
group
The PeerGroup |
protected boolean |
isReliable
If true then the socket is a stream socket otherwise it is a datagram socket. |
protected Credential |
localCredential
Our credential that we provide to the remote peer. |
protected PipeAdvertisement |
localEphemeralPipeAdv
Pipe Advertisement of local ephemeral pipe. |
protected InputPipe |
localEphemeralPipeIn
The input pipe for our ephemeral pipe. |
protected int |
maxRetryTimeout
maximum retry timeout allowed |
protected net.jxta.socket.JxtaSocketInputStream |
nonReliableInputStream
The unreliable input stream we use for receiving data if isReliable is false . |
protected net.jxta.socket.JxtaSocketOutputStream |
nonReliableOutputStream
The unreliable output stream we use for sending data if isReliable is false . |
protected Outgoing |
outgoing
Used for sending all messages by the reliable output and input streams. |
protected PipeAdvertisement |
pipeAdv
Pipe Advertisement of the well known pipe. |
protected Object |
pipeResolveLock
Lock for output pipe resolution. |
protected PipeService |
pipeSvc
|
protected Credential |
remoteCredential
Credential of the remote peer. |
protected PipeAdvertisement |
remoteEphemeralPipeAdv
Pipe Advertisement of it's ephemeral pipe. |
protected Messenger |
remoteEphemeralPipeMsgr
The Messenger we use to |
protected PeerID |
remotePeerID
The peer id of the peer we are connecting to or null if we are
willing to connect to any peer. |
protected int |
retryTimeout
retry timeout in millisecods |
protected ReliableInputStream |
ris
The reliable input stream we use for receiving data if isReliable is true . |
protected ReliableOutputStream |
ros
The reliable output stream we use for sending data if isReliable is true . |
protected Object |
socketConnectLock
Lock for ephemeral pipe connect states. |
protected long |
timeout
timeout for connect and close |
protected int |
windowSize
retry window size |
Constructor Summary | |
---|---|
|
JxtaSocket()
This constructor does not establish a connection. |
|
JxtaSocket(PeerGroup group,
PeerID peerid,
PipeAdvertisement pipeAdv,
int timeout)
Create a JxtaSocket to any peer listening on pipeAdv this attempts establish a connection to specified pipe within a context of group and within the timeout specified in milliseconds |
|
JxtaSocket(PeerGroup group,
PeerID peerid,
PipeAdvertisement pipeAdv,
int timeout,
boolean reliable)
Create a JxtaSocket to any peer listening on pipeAdv this attempts establish a connection to specified pipe within a context of group and within the timeout specified in milliseconds |
|
JxtaSocket(PeerGroup group,
PipeAdvertisement pipeAdv)
Create a JxtaSocket to any node listening on pipeAdv |
|
JxtaSocket(PeerGroup group,
PipeAdvertisement pipeAdv,
int timeout)
Create a JxtaSocket to any peer listening on pipeAdv this attempts establish a connection to specified pipe within the context of the specified group within timeout specified in milliseconds. |
protected |
JxtaSocket(PeerGroup group,
PipeAdvertisement pipeAdv,
PipeAdvertisement remoteEphemeralPipeAdv,
PeerAdvertisement remotePeerAdv,
Credential localCredential,
Credential remoteCredential,
boolean isReliable)
This constructor is used by JxtaServer socket for creating JxtaSocket instances in response to incoming connections. |
|
JxtaSocket(SocketAddress address)
Create a JxtaSocket connected to the give JxtaSocketAddress. |
|
JxtaSocket(SocketAddress address,
int timeout)
Create a JxtaSocket to the given JxtaSocketAddress, within the timeout specified in milliseconds. |
|
JxtaSocket(SocketAddress address,
int timeout,
boolean reliable)
Create a JxtaSocket to the given JxtaSocketAddress, within the timeout specified in milliseconds. |
Method Summary | |
---|---|
void |
bind(SocketAddress address)
Unsupported operation, an IOException will be thrown. |
void |
close()
We hard-close both the input and output streams. |
protected void |
closeFromRemote()
This is called when closure is initiated on the remote side. |
void |
connect(PeerGroup group,
PeerID peerid,
PipeAdvertisement pipeAdv,
int timeout)
Connects to a JxtaServerSocket on a specific peer within a timeout specified in milliseconds |
void |
connect(PeerGroup group,
PipeAdvertisement pipeAdv)
Connects to a JxtaServerSocket on any peer within the default timeout of 60 seconds |
void |
connect(PeerGroup group,
PipeAdvertisement pipeAdv,
int timeout)
Connects to a JxtaServerSocket on any peer within a timeout specified in milliseconds |
void |
connect(SocketAddress address)
The default connect timeout of 60 seconds is used If SocketAddress is not an instance of JxtaSocketAddress, an IOException will be thrown. |
void |
connect(SocketAddress address,
int timeout)
If SocketAddress is not an instance of JxtaSocketAddress, an IOException will be thrown. |
void |
create(boolean reliable)
Deprecated. Unreliable mode is being removed. Use JxtaBiDiPipe instead. |
protected Message |
createConnectMessage(PeerGroup group,
PipeAdvertisement pipeAdv,
Credential credential,
boolean isReliable,
boolean initiator)
Create a connection request/response message |
protected void |
finalize()
|
Credential |
getCredentialDoc()
get the remote credential doc |
protected static Credential |
getDefaultCredential(PeerGroup group)
obtain the cred doc from the group object |
InputStream |
getInputStream()
|
boolean |
getKeepAlive()
|
SocketAddress |
getLocalSocketAddress()
|
int |
getMaxRetryTimeout()
Deprecated. The reliability layer manages it's own maximum. This value is not useful. |
OutputStream |
getOutputStream()
|
int |
getOutputStreamBufferSize()
Deprecated. Use the standard getSendBufferSize() method instead. |
int |
getReceiveBufferSize()
|
SocketAddress |
getRemoteSocketAddress()
|
int |
getRetryTimeout()
Gets the Retry Timeout of the reliability layer |
int |
getSendBufferSize()
|
int |
getSoTimeout()
|
int |
getTrafficClass()
|
int |
getWindowSize()
When in reliable mode, gets the Reliable library window size |
boolean |
isBound()
|
boolean |
isClosed()
Returns the closed state of the JxtaSocket. |
boolean |
isConnected()
|
boolean |
isInputShutdown()
|
boolean |
isOutputShutdown()
|
protected static Messenger |
lightweightOutputPipe(PeerGroup group,
PipeAdvertisement pipeAdv,
PeerAdvertisement peerAdv)
A lightweight output pipe constructor, note the return type Since all the info needed is available, there's no need for to use the pipe service to resolve the pipe we have all we need to construct a messenger. |
protected Outgoing |
makeOutgoing(Messenger msgr,
long timeout)
Create an appropriate Outgoing Adaptor. |
protected static PipeAdvertisement |
newEphemeralPipeAdv(PipeAdvertisement pipeAdv)
Create a pipe advertisement for an ephemeral pipe (w/random pipe ID) from an existing pipe advertisement. |
void |
outputPipeEvent(OutputPipeEvent event)
Called when a input pipe has been located for a previously registered pipe. |
void |
pipeMsgEvent(PipeMsgEvent event)
Called for each pipe message event that occurs. |
void |
sendUrgentData(int data)
|
void |
setCredential(Credential localCredential)
Sets our credential to be used by this socket connection. |
void |
setKeepAlive(boolean state)
|
void |
setMaxRetryTimeout(int maxRetryTimeout)
Deprecated. The reliability layer manages it's own maximum. This value is not useful. |
void |
setOOBInline(boolean state)
|
void |
setOutputStreamBufferSize(int size)
Deprecated. Use the standard setSendBufferSize(int) method instead. |
void |
setRetryTimeout(int retryTimeout)
Sets the Retry Timeout of the underlying reliability layer. |
void |
setSendBufferSize(int size)
|
void |
setSoTimeout(int soTimeout)
|
void |
setTrafficClass(int tc)
|
void |
setWindowSize(int windowSize)
When in reliable mode, sets the Reliable library window size |
void |
shutdownInput()
|
void |
shutdownOutput()
|
String |
toString()
This output is suitable for debugging but should not be parsed. |
protected void |
unbind()
Closes the input pipe which we use to receive messages and the messenger used for sending messages. |
protected void |
write(byte[] buf,
int offset,
int length)
Performs on behalf of JxtaSocketOutputStream. |
Methods inherited from class java.net.Socket |
---|
getChannel, getInetAddress, getLocalAddress, getLocalPort, getOOBInline, getPort, getReuseAddress, getSoLinger, getTcpNoDelay, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSocketImplFactory, setSoLinger, setTcpNoDelay |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected PeerGroup group
protected PipeAdvertisement pipeAdv
protected PipeAdvertisement localEphemeralPipeAdv
protected InputPipe localEphemeralPipeIn
protected PipeAdvertisement remoteEphemeralPipeAdv
protected Messenger remoteEphemeralPipeMsgr
protected PipeService pipeSvc
protected PeerID remotePeerID
null
if we are
willing to connect to any peer.
protected OutputPipe connectOutpipe
protected long timeout
protected int retryTimeout
protected int maxRetryTimeout
protected int windowSize
protected final Object pipeResolveLock
protected final Object socketConnectLock
protected final Object closeLock
protected volatile boolean closed
true
then this socket has been closed and can no longer be used.
protected boolean bound
true
then we believer our end of the connection is open.
protected boolean connected
true
then we believe the remote peer currently has this socket open.
protected Credential remoteCredential
protected Credential localCredential
protected boolean isReliable
true
then the socket is a stream socket otherwise it is a datagram socket.
protected Outgoing outgoing
protected ReliableInputStream ris
isReliable
is true
.
protected ReliableOutputStream ros
isReliable
is true
.
protected net.jxta.socket.JxtaSocketInputStream nonReliableInputStream
isReliable
is false
.
protected net.jxta.socket.JxtaSocketOutputStream nonReliableOutputStream
isReliable
is false
.
Constructor Detail |
---|
public JxtaSocket()
protected JxtaSocket(PeerGroup group, PipeAdvertisement pipeAdv, PipeAdvertisement remoteEphemeralPipeAdv, PeerAdvertisement remotePeerAdv, Credential localCredential, Credential remoteCredential, boolean isReliable) throws IOException
group
- group contextpipeAdv
- The original PipeAdvertisementlocalCredential
- Our credential.remoteEphemeralPipeAdv
- the phemeral pipe advertisementremotePeerAdv
- remote peer advertisementremoteCredential
- The remote peer's credential.isReliable
- true
for reliable stream connection or
false
for unreliable stream connection.
IOException
- if an io error occurspublic JxtaSocket(SocketAddress address) throws IOException
address
- JxtaSocketAddress to connect to
IOException
- if an io error occurspublic JxtaSocket(PeerGroup group, PipeAdvertisement pipeAdv) throws IOException
group
- group contextpipeAdv
- PipeAdvertisement
IOException
- if an io error occurspublic JxtaSocket(SocketAddress address, int timeout) throws IOException
address
- JxtaSocket address to connect totimeout
- The number of milliseconds within which the socket must
be successfully created. An exception will be thrown if the socket
cannot be created in the allotted time. A timeout value of 0
(zero) specifies an infinite timeout.
IOException
- For failures in creating the socket.
SocketTimeoutException
- If the socket cannot be created before
the timeout occurs.public JxtaSocket(PeerGroup group, PipeAdvertisement pipeAdv, int timeout) throws IOException
group
- group contextpipeAdv
- PipeAdvertisementtimeout
- The number of milliseconds within which the socket must
be successfully created. An exception will be thrown if the socket
cannot be created in the allotted time. A timeout value of 0
(zero) specifies an infinite timeout.
IOException
- if an io error occurs
SocketTimeoutException
- If the socket cannot be created before
the timeout occurs.public JxtaSocket(PeerGroup group, PeerID peerid, PipeAdvertisement pipeAdv, int timeout) throws IOException
group
and within the timeout specified in milliseconds
group
- group contextpeerid
- node to connect topipeAdv
- PipeAdvertisementtimeout
- The number of milliseconds within which the socket must
be successfully created. An exception will be thrown if the socket
cannot be created in the allotted time. A timeout value of 0
(zero) specifies an infinite timeout.
IOException
- For failures in creating the socket.
SocketTimeoutException
- If the socket cannot be created before
the timeout occurs.public JxtaSocket(SocketAddress address, int timeout, boolean reliable) throws IOException
address
- JxtaSocket address to connect totimeout
- The number of milliseconds within which the socket must
be successfully created. An exception will be thrown if the socket
cannot be created in the allotted time. A timeout value of 0
(zero) specifies an infinite timeout.reliable
- true
for reliable stream connection or
false
for unreliable stream connection.
IOException
- For failures in creating the socket.
SocketTimeoutException
- If the socket cannot be created before
the timeout occurs.public JxtaSocket(PeerGroup group, PeerID peerid, PipeAdvertisement pipeAdv, int timeout, boolean reliable) throws IOException
group
and within the timeout specified in milliseconds
group
- group contextpeerid
- node to connect topipeAdv
- PipeAdvertisementtimeout
- The number of milliseconds within which the socket must
be successfully created. An exception will be thrown if the socket
cannot be created in the allotted time. A timeout value of 0
(zero) specifies an infinite timeout.reliable
- true
for reliable stream connection or
false
for unreliable stream connection.
IOException
- For failures in creating the socket.
SocketTimeoutException
- If the socket cannot be created before
the timeout occurs.Method Detail |
---|
protected void finalize() throws Throwable
finalize
in class Object
Throwable
@Deprecated public void create(boolean reliable) throws IOException
reliable
- true
for reliable stream connection or false
for unreliable stream connection.
IOException
- if an I/O error occurs while creating the socket.public void bind(SocketAddress address) throws IOException
bind
in class Socket
IOException
- Thrown in all cases as this operation is not supported.public void connect(SocketAddress address) throws IOException
connect
in class Socket
IOException
public void connect(SocketAddress address, int timeout) throws IOException
connect
in class Socket
IOException
public void connect(PeerGroup group, PipeAdvertisement pipeAdv) throws IOException
group
- group contextpipeAdv
- PipeAdvertisement
IOException
- if an io error occurspublic void connect(PeerGroup group, PipeAdvertisement pipeAdv, int timeout) throws IOException
group
- group contextpipeAdv
- PipeAdvertisementtimeout
- in milliseconds
IOException
- if an io error occurspublic void connect(PeerGroup group, PeerID peerid, PipeAdvertisement pipeAdv, int timeout) throws IOException
group
- group contextpeerid
- peer to connect topipeAdv
- PipeAdvertisementtimeout
- timeout in milliseconds
IOException
- if an io error occursprotected static Credential getDefaultCredential(PeerGroup group)
group
- the group context
Credential
valuepublic Credential getCredentialDoc()
public void setCredential(Credential localCredential)
localCredential
- The credential to be used for connection responses
or null if the default credential is to be used.protected Message createConnectMessage(PeerGroup group, PipeAdvertisement pipeAdv, Credential credential, boolean isReliable, boolean initiator) throws IOException
group
- The group in which the socket is being used.pipeAdv
- Advertisement for our ephemeral pipe.credential
- Our credential or null if default credential is to
be used.isReliable
- The socket is to be reliable (stream).initiator
- indicates initiator
IOException
- if an I/O error occursprotected static PipeAdvertisement newEphemeralPipeAdv(PipeAdvertisement pipeAdv)
pipeAdv
- to get the basename and type from
public boolean isBound()
isBound
in class Socket
public boolean isConnected()
isConnected
in class Socket
protected Outgoing makeOutgoing(Messenger msgr, long timeout)
msgr
- The messenger to be wrapped.timeout
- The timeout value;
@Deprecated public int getOutputStreamBufferSize()
getSendBufferSize()
method instead.
@Deprecated public void setOutputStreamBufferSize(int size) throws IOException
setSendBufferSize(int)
method instead.
size
- The internal buffer size.
IOException
- if an I/O error occurspublic InputStream getInputStream() throws IOException
getInputStream
in class Socket
IOException
public OutputStream getOutputStream() throws IOException
getOutputStream
in class Socket
IOException
public void close() throws IOException
synchronized
.
All others use internal synchronization.
close
in class Socket
IOException
protected void closeFromRemote() throws IOException
IOException
- if an I/O error occursprotected void unbind()
public void pipeMsgEvent(PipeMsgEvent event)
pipeMsgEvent
in interface PipeMsgListener
event
- The event being received.public void outputPipeEvent(OutputPipeEvent event)
OutputPipe
which can
be used to communicate with the remote peer.
outputPipeEvent
in interface OutputPipeListener
event
- the eventprotected static Messenger lightweightOutputPipe(PeerGroup group, PipeAdvertisement pipeAdv, PeerAdvertisement peerAdv)
group
- group contextpipeAdv
- Remote Pipe AdvertisementpeerAdv
- Remote Peer Advertisement
public int getSoTimeout() throws SocketException
getSoTimeout
in class Socket
SocketException
public void setSoTimeout(int soTimeout) throws SocketException
setSoTimeout
in class Socket
SocketException
@Deprecated public int getMaxRetryTimeout()
@Deprecated public void setMaxRetryTimeout(int maxRetryTimeout)
maxRetryTimeout
- The new maximum retry timeout value
IllegalArgumentException
- if maxRetryTimeout exceeds jxta platform maximum retry timeoutpublic int getRetryTimeout()
public void setRetryTimeout(int retryTimeout) throws SocketException
retryTimeout
- The new retry timeout value
SocketException
- if an I/O error occurspublic int getWindowSize()
public void setWindowSize(int windowSize) throws SocketException
windowSize
- The new window size value
SocketException
- if an I/O error occurspublic boolean isClosed()
isClosed
in class Socket
protected void write(byte[] buf, int offset, int length) throws IOException
buf
- the data.offset
- the start offset in the data.length
- the number of bytes to write.
IOException
- if an I/O error occursOutputStream.write(int)
public int getSendBufferSize() throws SocketException
getSendBufferSize
in class Socket
SocketException
public void setSendBufferSize(int size) throws SocketException
setSendBufferSize
in class Socket
SocketException
public int getReceiveBufferSize() throws SocketException
getReceiveBufferSize
in class Socket
SocketException
public boolean getKeepAlive() throws SocketException
getKeepAlive
in class Socket
SocketException
public int getTrafficClass() throws SocketException
getTrafficClass
in class Socket
SocketException
public void setTrafficClass(int tc) throws SocketException
setTrafficClass
in class Socket
SocketException
public boolean isInputShutdown()
isInputShutdown
in class Socket
public boolean isOutputShutdown()
isOutputShutdown
in class Socket
public void sendUrgentData(int data) throws IOException
sendUrgentData
in class Socket
IOException
public void setOOBInline(boolean state) throws SocketException
setOOBInline
in class Socket
SocketException
public void setKeepAlive(boolean state) throws SocketException
setKeepAlive
in class Socket
SocketException
public void shutdownInput() throws IOException
shutdownInput
in class Socket
IOException
public void shutdownOutput() throws IOException
shutdownOutput
in class Socket
IOException
public SocketAddress getLocalSocketAddress()
getLocalSocketAddress
in class Socket
public SocketAddress getRemoteSocketAddress()
getRemoteSocketAddress
in class Socket
public String toString()
toString
in class Socket
|
JXSE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |