Package com.hierynomus.smbj.connection
Class Connection
- java.lang.Object
-
- com.hierynomus.smbj.common.Pooled<Connection>
-
- com.hierynomus.smbj.connection.Connection
-
- All Implemented Interfaces:
PacketReceiver<SMBPacketData<?>>
,java.io.Closeable
,java.lang.AutoCloseable
public class Connection extends Pooled<Connection> implements java.io.Closeable, PacketReceiver<SMBPacketData<?>>
A connection to a server.
-
-
Constructor Summary
Constructors Constructor Description Connection(Connection connection)
Connection(SmbConfig config, SMBClient client, SMBEventBus bus, ServerList serverList)
-
Method Summary
Modifier and Type Method Description Session
authenticate(AuthenticationContext authContext)
Authenticate the user on this connection in order to start a (new) session.void
close()
void
close(boolean force)
Close the Connection.void
connect(java.lang.String hostname, int port)
SMBClient
getClient()
ConnectionContext
getConnectionContext()
NegotiatedProtocol
getNegotiatedProtocol()
Returns the negotiated protocol details for this connection.java.lang.String
getRemoteHostname()
void
handle(SMBPacketData<?> uncheckedPacket)
void
handleError(java.lang.Throwable t)
boolean
isConnected()
<T extends SMB2Packet>
java.util.concurrent.Future<T>send(SMB2Packet packet)
send a packet.
-
-
-
Constructor Detail
-
Connection
public Connection(SmbConfig config, SMBClient client, SMBEventBus bus, ServerList serverList)
-
Connection
public Connection(Connection connection)
-
-
Method Detail
-
getClient
public SMBClient getClient()
-
connect
public void connect(java.lang.String hostname, int port) throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
close
public void close(boolean force) throws java.io.IOException
Close the Connection. Ifforce
is set to true, it forgoes theSession.close()
operation on the open sessions, and it just calls theTransportLayer.disconnect()
.If
force
is set to false, the usage counter of the connection reduces with one. If the usage count drops to zero the connection will be closed.- Parameters:
force
- if set, does not nicely terminate the open sessions.- Throws:
java.io.IOException
- If any error occurred during close-ing.
-
authenticate
public Session authenticate(AuthenticationContext authContext)
Authenticate the user on this connection in order to start a (new) session.- Returns:
- a (new) Session that is authenticated for the user.
-
send
public <T extends SMB2Packet> java.util.concurrent.Future<T> send(SMB2Packet packet) throws TransportException
send a packet.- Parameters:
packet
- SMBPacket to send- Returns:
- a Future to be used to retrieve the response packet
- Throws:
TransportException
- When a transport level error occurred
-
getNegotiatedProtocol
public NegotiatedProtocol getNegotiatedProtocol()
Returns the negotiated protocol details for this connection.- Returns:
- The negotiated protocol details
-
handle
public void handle(SMBPacketData<?> uncheckedPacket) throws TransportException
- Specified by:
handle
in interfacePacketReceiver<SMBPacketData<?>>
- Throws:
TransportException
-
handleError
public void handleError(java.lang.Throwable t)
- Specified by:
handleError
in interfacePacketReceiver<SMBPacketData<?>>
-
getRemoteHostname
public java.lang.String getRemoteHostname()
-
isConnected
public boolean isConnected()
-
getConnectionContext
public ConnectionContext getConnectionContext()
-
-