Top Description Inners Methods
org.glassfish.grizzly

public Interface Writer<L>

Known Direct Subinterfaces
org.glassfish.grizzly.asyncqueue.AsyncQueueWriter
Known Direct Implementers
org.glassfish.grizzly.AbstractWriter
Annotations
@SuppressWarnings:deprecation
Type Parameters
<L>
the writer address type
Imports
java.io.IOException, java.util.concurrent.Future, org.glassfish.grizzly.asyncqueue.MessageCloner, .WritableMessage

Implementations of this interface are able to write data from a Buffer to Connection. There are two basic Writer implementations in Grizzly: org.glassfish.grizzly.asyncqueue.AsyncQueueWriter, org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorWriter.
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Writer.Reentrant

Write reentrants counter

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the connection has not exceeded it's maximum size in bytes of pending writes, otherwise false
canWrite
(final Connection<L>
the Connection to test whether or not the specified number of bytes can be written to.
connection
)

Return true if the connection has not exceeded it's maximum size in bytes of pending writes, otherwise false.

public void
notifyWritePossible(final Connection<L> connection, final WriteHandler
WriteHandler to be notified.
writeHandler
)

Registers WriteHandler, which will be notified ones at least one byte can be written.

public GrizzlyFuture<WriteResult<WritableMessage, L>>

Returns:

Future, using which it's possible to check the result
write
(Connection<L> connection, WritableMessage
the WritableMessage, from which the data will be written
message
)

Method writes the WritableMessage.

public void
write(Connection<L> connection, WritableMessage
the WritableMessage, from which the data will be written
message
,
CompletionHandler<WriteResult<WritableMessage, L>>
org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed
completionHandler
)

Method writes the WritableMessage.

public GrizzlyFuture<WriteResult<WritableMessage, L>>

Returns:

Future, using which it's possible to check the result
write
(Connection<L> connection, L
the destination address the WritableMessage will be sent to
dstAddress
,
WritableMessage
the WritableMessage, from which the data will be written
message
)

Method writes the WritableMessage to the specific address.

public void
write(Connection<L> connection, L
the destination address the WritableMessage will be sent to
dstAddress
,
WritableMessage
the WritableMessage, from which the data will be written
message
,
CompletionHandler<WriteResult<WritableMessage, L>>
org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed
completionHandler
)

Method writes the WritableMessage to the specific address.

public void
write(Connection<L> connection, L
the destination address the WritableMessage will be sent to
dstAddress
,
WritableMessage
the WritableMessage, from which the data will be written
message
,
CompletionHandler<WriteResult<WritableMessage, L>>
org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed
completionHandler
,
PushBackHandler
org.glassfish.grizzly.asyncqueue.PushBackHandler, which will be notified if message was accepted by transport write queue or refused
pushBackHandler
)
Deprecated push back logic is deprecated

Method writes the WritableMessage to the specific address.

public void
write(Connection<L> connection, L
the destination address the WritableMessage will be sent to
dstAddress
,
WritableMessage
the WritableMessage, from which the data will be written
message
,
CompletionHandler<WriteResult<WritableMessage, L>>
org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed
completionHandler
,
MessageCloner<WritableMessage>
the MessageCloner, which will be able to clone the message in case it can't be completely written in the current thread.
messageCloner
)

Method writes the WritableMessage to the specific address.

Method Detail

canWriteback to summary
public boolean canWrite(final Connection<L> connection)

Return true if the connection has not exceeded it's maximum size in bytes of pending writes, otherwise false.

Parameters
connection:Connection<L>

the Connection to test whether or not the specified number of bytes can be written to.

Returns:boolean

true if the connection has not exceeded it's maximum size in bytes of pending writes, otherwise false

Since
2.3
notifyWritePossibleback to summary
public void notifyWritePossible(final Connection<L> connection, final WriteHandler writeHandler)

Registers WriteHandler, which will be notified ones at least one byte can be written. This method call is equivalent to call notifyWritePossible(connection, writeHandler, 1); Note: using this method from different threads simultaneously may lead to quick situation changes, so at time WriteHandler is called - the queue may become busy again.

Parameters
connection:Connection<L>

Connection

writeHandler:WriteHandler

WriteHandler to be notified.

Since
2.3
writeback to summary
public GrizzlyFuture<WriteResult<WritableMessage, L>> write(Connection<L> connection, WritableMessage message) throws IOException

Method writes the WritableMessage.

Parameters
connection:Connection<L>

the org.glassfish.grizzly.Connection to write to

message:WritableMessage

the WritableMessage, from which the data will be written

Returns:GrizzlyFuture<WriteResult<WritableMessage, L>>

Future, using which it's possible to check the result

Exceptions
IOException:
not thrown
writeback to summary
public void write(Connection<L> connection, WritableMessage message, CompletionHandler<WriteResult<WritableMessage, L>> completionHandler)

Method writes the WritableMessage.

Parameters
connection:Connection<L>

the org.glassfish.grizzly.Connection to write to

message:WritableMessage

the WritableMessage, from which the data will be written

completionHandler:CompletionHandler<WriteResult<WritableMessage, L>>

org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed

writeback to summary
public GrizzlyFuture<WriteResult<WritableMessage, L>> write(Connection<L> connection, L dstAddress, WritableMessage message)

Method writes the WritableMessage to the specific address.

Parameters
connection:Connection<L>

the org.glassfish.grizzly.Connection to write to

dstAddress:L

the destination address the WritableMessage will be sent to

message:WritableMessage

the WritableMessage, from which the data will be written

Returns:GrizzlyFuture<WriteResult<WritableMessage, L>>

Future, using which it's possible to check the result

writeback to summary
public void write(Connection<L> connection, L dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage, L>> completionHandler)

Method writes the WritableMessage to the specific address.

Parameters
connection:Connection<L>

the org.glassfish.grizzly.Connection to write to

dstAddress:L

the destination address the WritableMessage will be sent to

message:WritableMessage

the WritableMessage, from which the data will be written

completionHandler:CompletionHandler<WriteResult<WritableMessage, L>>

org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed

writeback to summary
public void write(Connection<L> connection, L dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage, L>> completionHandler, PushBackHandler pushBackHandler)

Deprecated

push back logic is deprecated

Method writes the WritableMessage to the specific address.

Parameters
connection:Connection<L>

the org.glassfish.grizzly.Connection to write to

dstAddress:L

the destination address the WritableMessage will be sent to

message:WritableMessage

the WritableMessage, from which the data will be written

completionHandler:CompletionHandler<WriteResult<WritableMessage, L>>

org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed

pushBackHandler:PushBackHandler

org.glassfish.grizzly.asyncqueue.PushBackHandler, which will be notified if message was accepted by transport write queue or refused

Annotations
@Deprecated
writeback to summary
public void write(Connection<L> connection, L dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage, L>> completionHandler, MessageCloner<WritableMessage> messageCloner)

Method writes the WritableMessage to the specific address.

Parameters
connection:Connection<L>

the org.glassfish.grizzly.Connection to write to

dstAddress:L

the destination address the WritableMessage will be sent to

message:WritableMessage

the WritableMessage, from which the data will be written

completionHandler:CompletionHandler<WriteResult<WritableMessage, L>>

org.glassfish.grizzly.CompletionHandler, which will get notified, when write will be completed

messageCloner:MessageCloner<WritableMessage>

the MessageCloner, which will be able to clone the message in case it can't be completely written in the current thread.

org.glassfish.grizzly back to summary

public final Class Writer.Reentrant

extends Object
Class Inheritance

Write reentrants counter

Field Summary

Modifier and TypeField and Description
private int
private static final int
private static final ThreadLocal<Writer.Reentrant>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the counter (after decrementing) didn't reach getMaxReentrants() limit, or false otherwise.
dec
()

Decrements the reentrants counter by one.

public int
get()

Returns the value of the reentrants counter for the current thread.

public static int

Returns:

the maximum number of write() method reentrants a thread is allowed to make.
getMaxReentrants
()

Returns the maximum number of write() method reentrants a thread is allowed to made.

public static Writer.Reentrant

Returns:

current reentrants counter
getWriteReentrant
()

Returns the current write reentrants counter.

public boolean

Returns:

true if the counter (after incrementing) didn't reach getMaxReentrants() limit, or false otherwise.
inc
()

Increments the reentrants counter by one.

public boolean

Returns:

true, if max number of write->completion-handler reentrants has been reached for the passed Reentrant object, and next write will happen in the separate thread.
isMaxReentrantsReached
()

Returns true, if max number of write->completion-handler reentrants has been reached for the passed Reentrant object, and next write will happen in the separate thread.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

counterback to summary
private int counter
maxWriteReentrantsback to summary
private static final int maxWriteReentrants
REENTRANTS_COUNTERback to summary
private static final ThreadLocal<Writer.Reentrant> REENTRANTS_COUNTER

Constructor Detail

Reentrantback to summary
public Reentrant()

Method Detail

decback to summary
public boolean dec()

Decrements the reentrants counter by one.

Returns:boolean

true if the counter (after decrementing) didn't reach getMaxReentrants() limit, or false otherwise.

getback to summary
public int get()

Returns the value of the reentrants counter for the current thread.

getMaxReentrantsback to summary
public static int getMaxReentrants()

Returns the maximum number of write() method reentrants a thread is allowed to made. This is related to possible write()->onComplete()->write()->... chain, which may grow infinitely and cause StackOverflow. Using maxWriteReentrants value it's possible to limit such a chain.

Returns:int

the maximum number of write() method reentrants a thread is allowed to make.

getWriteReentrantback to summary
public static Writer.Reentrant getWriteReentrant()

Returns the current write reentrants counter. Might be useful, if developer wants to use custom notification mechanism, based on on canWrite(org.glassfish.grizzly.Connection) and various write methods.

Returns:Writer.Reentrant

current reentrants counter

incback to summary
public boolean inc()

Increments the reentrants counter by one.

Returns:boolean

true if the counter (after incrementing) didn't reach getMaxReentrants() limit, or false otherwise.

isMaxReentrantsReachedback to summary
public boolean isMaxReentrantsReached()

Returns true, if max number of write->completion-handler reentrants has been reached for the passed Reentrant object, and next write will happen in the separate thread.

Returns:boolean

true, if max number of write->completion-handler reentrants has been reached for the passed Reentrant object, and next write will happen in the separate thread.