Skip to content

Package: StandaloneProcessor

StandaloneProcessor

nameinstructionbranchcomplexitylinemethod
StandaloneProcessor()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStreamReader(Connection)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStreamWriter(Connection)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isInterested(IOEvent)
M: 10 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
obtainContext(Connection)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
process(Context)
M: 43 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
read(Connection, CompletionHandler)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setInterested(IOEvent, boolean)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
write(Connection, Object, Object, CompletionHandler)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
write(Connection, Object, Object, CompletionHandler, MessageCloner)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
write(Connection, Object, Object, CompletionHandler, PushBackHandler)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.glassfish.grizzly;
18:
19: import java.net.Socket;
20:
21: import org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport;
22: import org.glassfish.grizzly.asyncqueue.AsyncQueueReader;
23: import org.glassfish.grizzly.asyncqueue.AsyncQueueWriter;
24: import org.glassfish.grizzly.asyncqueue.MessageCloner;
25: import org.glassfish.grizzly.filterchain.FilterChain;
26: import org.glassfish.grizzly.nio.transport.DefaultStreamReader;
27: import org.glassfish.grizzly.nio.transport.DefaultStreamWriter;
28: import org.glassfish.grizzly.streams.StreamReader;
29: import org.glassfish.grizzly.streams.StreamWriter;
30:
31: /**
32: * {@link Processor}, which is not interested in processing I/O events. {@link Connection} lifecycle should be managed
33: * explicitly, using read/write/accept/connect methods.
34: *
35: * This {@link Processor} could be set on {@link Connection} to avoid it from being processed by {@link FilterChain} or
36: * other {@link Processor}. In this case {@link Connection} could be used like regular Java {@link Socket}.
37: *
38: * @author Alexey Stashok
39: */
40: @SuppressWarnings({ "unchecked", "deprecation" })
41: public class StandaloneProcessor implements Processor {
42: public static final StandaloneProcessor INSTANCE = new StandaloneProcessor();
43:
44: /**
45: * This method should never be called, because {@link StandaloneProcessor#isInterested(IOEvent)} returns false for any
46: * {@link IOEvent}.
47: */
48: @Override
49: public ProcessorResult process(final Context context) {
50: final IOEvent iOEvent = context.getIoEvent();
51:• if (iOEvent == IOEvent.READ) {
52: final Connection connection = context.getConnection();
53: final AsyncQueueReader reader = ((AsyncQueueEnabledTransport) connection.getTransport()).getAsyncQueueIO().getReader();
54:
55: return reader.processAsync(context).toProcessorResult();
56:• } else if (iOEvent == IOEvent.WRITE) {
57: final Connection connection = context.getConnection();
58: final AsyncQueueWriter writer = ((AsyncQueueEnabledTransport) connection.getTransport()).getAsyncQueueIO().getWriter();
59:
60: return writer.processAsync(context).toProcessorResult();
61: }
62:
63: throw new IllegalStateException("Unexpected IOEvent=" + iOEvent);
64: }
65:
66: /**
67: * {@link StandaloneProcessor} is not interested in any {@link IOEvent}.
68: */
69: @Override
70: public boolean isInterested(IOEvent ioEvent) {
71:• return ioEvent == IOEvent.READ || ioEvent == IOEvent.WRITE;
72: }
73:
74: /**
75: * Method does nothing.
76: */
77: @Override
78: public void setInterested(IOEvent ioEvent, boolean isInterested) {
79: }
80:
81: @Override
82: public Context obtainContext(final Connection connection) {
83: final Context context = Context.create(connection);
84: context.setProcessor(this);
85: return context;
86: }
87:
88: /**
89: * Get the {@link Connection} {@link StreamReader}, to read data from the {@link Connection}.
90: *
91: * @param connection {@link Connection} to get the {@link StreamReader} for
92: * @return the {@link Connection} {@link StreamReader}, to read data from the {@link Connection}.
93: */
94: public StreamReader getStreamReader(Connection connection) {
95: return new DefaultStreamReader(connection);
96: }
97:
98: /**
99: * Get the {@link Connection} {@link StreamWriter}, to write data to the {@link Connection}.
100: *
101: * @param connection connection to get the {@link StreamWriter} for
102: * @return the {@link Connection} {@link StreamWriter}, to write data to the {@link Connection}.
103: */
104: public StreamWriter getStreamWriter(Connection connection) {
105: return new DefaultStreamWriter(connection);
106: }
107:
108: @Override
109: public void read(Connection connection, CompletionHandler completionHandler) {
110:
111: final Transport transport = connection.getTransport();
112: transport.getReader(connection).read(connection, null, completionHandler);
113: }
114:
115: @Override
116: public void write(final Connection connection, final Object dstAddress, final Object message, final CompletionHandler completionHandler) {
117: write(connection, dstAddress, message, completionHandler, (MessageCloner) null);
118: }
119:
120: @Override
121: public void write(Connection connection, Object dstAddress, Object message, CompletionHandler completionHandler, MessageCloner messageCloner) {
122:
123: final Transport transport = connection.getTransport();
124:
125: transport.getWriter(connection).write(connection, dstAddress, (Buffer) message, completionHandler, messageCloner);
126: }
127:
128: @Override
129: @Deprecated
130: public void write(Connection connection, Object dstAddress, Object message, CompletionHandler completionHandler,
131: org.glassfish.grizzly.asyncqueue.PushBackHandler pushBackHandler) {
132:
133: final Transport transport = connection.getTransport();
134:
135: transport.getWriter(connection).write(connection, dstAddress, (Buffer) message, completionHandler, pushBackHandler);
136: }
137: }