Skip to content

Package: ProcessorExecutor

ProcessorExecutor

nameinstructionbranchcomplexitylinemethod
ProcessorExecutor()
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%
complete(Context, Object)
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
complete(Context, ProcessorResult)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
complete0(Context, ProcessorResult)
M: 35 C: 0
0%
M: 7 C: 0
0%
M: 7 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%
error(Context, Object)
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
execute(Connection, IOEvent, Processor, IOEventLifeCycleListener)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
execute(Context)
M: 77 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
leave(Context)
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
notRun(Context)
M: 24 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
reregister(Context, Object)
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
rerun(Context, Context)
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
resume(Context)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 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.io.IOException;
20: import java.util.logging.Level;
21: import java.util.logging.Logger;
22:
23: import org.glassfish.grizzly.localization.LogMessages;
24:
25: /**
26: *
27: * @author oleksiys
28: */
29: public final class ProcessorExecutor {
30:
31: private static final Logger LOGGER = Grizzly.logger(ProcessorExecutor.class);
32:
33: public static void execute(final Connection connection, final IOEvent ioEvent, final Processor processor,
34: final IOEventLifeCycleListener lifeCycleListener) {
35:
36: execute(Context.create(connection, processor, ioEvent, lifeCycleListener));
37: }
38:
39: @SuppressWarnings("unchecked")
40: public static void execute(Context context) {
41:• if (LOGGER.isLoggable(Level.FINEST)) {
42: LOGGER.log(Level.FINEST, "executing connection ({0}). IOEvent={1} processor={2}",
43: new Object[] { context.getConnection(), context.getIoEvent(), context.getProcessor() });
44: }
45:
46: boolean isRerun;
47: ProcessorResult result;
48:
49: try {
50: do {
51: result = context.getProcessor().process(context);
52:• isRerun = result.getStatus() == ProcessorResult.Status.RERUN;
53:• if (isRerun) {
54: final Context newContext = (Context) result.getData();
55: rerun(context, newContext);
56: context = newContext;
57: }
58:• } while (isRerun);
59:
60: complete0(context, result);
61:
62: } catch (Throwable t) {
63:• if (LOGGER.isLoggable(Level.WARNING)) {
64: LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_PROCESSOR_ERROR(context.getConnection(), context.getIoEvent(), context.getProcessor()),
65: t);
66: }
67:
68: try {
69: error(context, t);
70: } catch (Exception ignored) {
71: }
72: }
73: }
74:
75: public static void resume(final Context context) throws IOException {
76: execute(context);
77: }
78:
79: private static void complete(final Context context, final Object data) throws IOException {
80:
81: final int sz = context.lifeCycleListeners.size();
82: final IOEventLifeCycleListener[] listeners = context.lifeCycleListeners.array();
83: try {
84:• for (int i = 0; i < sz; i++) {
85: listeners[i].onComplete(context, data);
86: }
87: } finally {
88: context.recycle();
89: }
90: }
91:
92: private static void leave(final Context context) throws IOException {
93: final int sz = context.lifeCycleListeners.size();
94: final IOEventLifeCycleListener[] listeners = context.lifeCycleListeners.array();
95: try {
96:• for (int i = 0; i < sz; i++) {
97: listeners[i].onLeave(context);
98: }
99: } finally {
100: context.recycle();
101: }
102: }
103:
104: private static void reregister(final Context context, final Object data) throws IOException {
105:
106: // "Context context" was suspended, so we reregister with its copy
107: // which is passed as "Object data"
108: final Context realContext = (Context) data;
109:
110: final int sz = context.lifeCycleListeners.size();
111: final IOEventLifeCycleListener[] listeners = context.lifeCycleListeners.array();
112: try {
113:• for (int i = 0; i < sz; i++) {
114: listeners[i].onReregister(realContext);
115: }
116: } finally {
117: realContext.recycle();
118: }
119: }
120:
121: private static void rerun(final Context context, final Context newContext) throws IOException {
122:
123: final int sz = context.lifeCycleListeners.size();
124: final IOEventLifeCycleListener[] listeners = context.lifeCycleListeners.array();
125:• for (int i = 0; i < sz; i++) {
126: listeners[i].onRerun(context, newContext);
127: }
128: }
129:
130: private static void error(final Context context, final Object description) throws IOException {
131: final int sz = context.lifeCycleListeners.size();
132: final IOEventLifeCycleListener[] listeners = context.lifeCycleListeners.array();
133: try {
134:• for (int i = 0; i < sz; i++) {
135: listeners[i].onError(context, description);
136: }
137: } finally {
138: context.release();
139: }
140: }
141:
142: private static void notRun(final Context context) throws IOException {
143: final int sz = context.lifeCycleListeners.size();
144: final IOEventLifeCycleListener[] listeners = context.lifeCycleListeners.array();
145: try {
146:• for (int i = 0; i < sz; i++) {
147: listeners[i].onNotRun(context);
148: }
149: } finally {
150: context.recycle();
151: }
152: }
153:
154: static void complete(final Context context, final ProcessorResult result) {
155:
156: try {
157: complete0(context, result);
158: } catch (Throwable t) {
159: try {
160: error(context, t);
161: } catch (Exception ignored) {
162: }
163: }
164: }
165:
166: private static void complete0(final Context context, final ProcessorResult result) throws IllegalStateException, IOException {
167:
168: final ProcessorResult.Status status = result.getStatus();
169:
170:• switch (status) {
171: case COMPLETE:
172: complete(context, result.getData());
173: break;
174:
175: case LEAVE:
176: leave(context);
177: break;
178:
179: case TERMINATE:
180: // terminate(context);
181: break;
182:
183: case REREGISTER:
184: reregister(context, result.getData());
185: break;
186:
187: case ERROR:
188: error(context, result.getData());
189: break;
190:
191: case NOT_RUN:
192: notRun(context);
193: break;
194:
195: default:
196: throw new IllegalStateException();
197: }
198: }
199: }