com.mongodb.connection.Stream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mongodb-driver-core Show documentation
Show all versions of mongodb-driver-core Show documentation
The Java operations layer for the MongoDB Java Driver. Third parties can ' +
'wrap this layer to provide custom higher-level APIs
/*
* Copyright 2008-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mongodb.connection;
import com.mongodb.ServerAddress;
import org.bson.ByteBuf;
import java.io.IOException;
import java.util.List;
/**
* A full duplex stream of bytes.
*
* @since 3.0
* @deprecated There is no replacement for this interface.
*/
@Deprecated
public interface Stream extends BufferProvider{
/**
* Open the stream.
*
* @throws IOException if an I/O error occurs
*/
void open() throws IOException;
/**
* Open the stream asynchronously.
*
* @param handler the completion handler for opening the stream
*/
void openAsync(AsyncCompletionHandler handler);
/**
* Write each buffer in the list to the stream in order, blocking until all are completely written.
*
* @param buffers the buffers to write. The operation must not {@linkplain ByteBuf#release() release} any buffer from {@code buffers},
* unless the operation {@linkplain ByteBuf#retain() retains} it, and releasing is meant to compensate for that.
* @throws IOException if there are problems writing to the stream
*/
void write(List buffers) throws IOException;
/**
* Read from the stream, blocking until the requested number of bytes have been read.
*
* @param numBytes The number of bytes to read into the returned byte buffer
* @return a byte buffer filled with number of bytes requested
* @throws IOException if there are problems reading from the stream
*/
ByteBuf read(int numBytes) throws IOException;
/**
* Gets whether this implementation supports specifying an additional timeout for read operations
*
* The default is to not support specifying an additional timeout
*
*
* @return true if this implementation supports specifying an additional timeouts for reads operations
* @see #read(int, int)
* @since 4.1
*/
default boolean supportsAdditionalTimeout() {
return false;
}
/**
* Read from the stream, blocking until the requested number of bytes have been read. If supported by the implementation,
* adds the given additional timeout to the configured timeout for the stream.
*
* This method should not be called unless {@link #supportsAdditionalTimeout()} returns true.
*
*
* The default behavior is to throw an {@link UnsupportedOperationException}
*
*
* @param numBytes The number of bytes to read into the returned byte buffer
* @param additionalTimeout additional timeout in milliseconds to add to the configured timeout
* @return a byte buffer filled with number of bytes requested
* @throws IOException if there are problems reading from the stream
* @throws UnsupportedOperationException if this implementation does not support additional timeouts
* @see #supportsAdditionalTimeout()
* @since 4.1
*/
default ByteBuf read(int numBytes, int additionalTimeout) throws IOException {
throw new UnsupportedOperationException();
}
/**
* Write each buffer in the list to the stream in order, asynchronously. This method should return immediately, and invoke the given
* callback on completion.
*
* @param buffers the buffers to write. The operation must not {@linkplain ByteBuf#release() release} any buffer from {@code buffers},
* unless the operation {@linkplain ByteBuf#retain() retains} it, and releasing is meant to compensate for that.
* @param handler invoked when the write operation has completed
*/
void writeAsync(List buffers, AsyncCompletionHandler handler);
/**
* Read from the stream, asynchronously. This method should return immediately, and invoke the given callback when the number of
* requested bytes have been read.
*
* @param numBytes the number of bytes
* @param handler invoked when the read operation has completed
*/
void readAsync(int numBytes, AsyncCompletionHandler handler);
/**
* The address that this stream is connected to.
*
* @return the address
*/
ServerAddress getAddress();
/**
* Closes the connection.
*/
void close();
/**
* Returns the closed state of the connection
*
* @return true if connection is closed
*/
boolean isClosed();
}