Skip to content

Package: ReadResult

ReadResult

nameinstructionbranchcomplexitylinemethod
ReadResult()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
ReadResult(Connection)
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%
ReadResult(Connection, Object, Object, int)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
checkRecycled()
M: 11 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
copy()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
create(Connection)
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
create(Connection, Object, Object, int)
M: 30 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getConnection()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getMessage()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getReadSize()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getSrcAddress()
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getSrcAddressHolder()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
recycle()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
reset()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
set(Connection, Object, Object, int)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
setMessage(Object)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setReadSize(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setSrcAddress(Object)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setSrcAddressHolder(Holder)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 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%
takeFromCache()
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 org.glassfish.grizzly.utils.Holder;
20:
21: /**
22: * Result of read operation, returned by {@link Readable}.
23: *
24: * @param <K> type of the message
25: * @param <L> type of the address
26: *
27: * @author Alexey Stashok
28: */
29: public class ReadResult<K, L> implements Result, Cacheable {
30: private static final ThreadCache.CachedTypeIndex<ReadResult> CACHE_IDX = ThreadCache.obtainIndex(ReadResult.class, 4);
31:
32: private boolean isRecycled = false;
33:
34: public static <K, L> ReadResult<K, L> create(Connection<L> connection) {
35: final ReadResult<K, L> readResult = takeFromCache();
36:• if (readResult != null) {
37: readResult.connection = connection;
38: readResult.isRecycled = false;
39: return readResult;
40: }
41:
42: return new ReadResult<>(connection);
43: }
44:
45: public static <K, L> ReadResult<K, L> create(Connection<L> connection, K message, L srcAddress, int readSize) {
46: final ReadResult<K, L> readResult = takeFromCache();
47:• if (readResult != null) {
48: readResult.connection = connection;
49: readResult.message = message;
50: readResult.srcAddressHolder = Holder.staticHolder(srcAddress);
51: readResult.readSize = readSize;
52: readResult.isRecycled = false;
53:
54: return readResult;
55: }
56:
57: return new ReadResult<>(connection, message, srcAddress, readSize);
58: }
59:
60: @SuppressWarnings("unchecked")
61: private static <K, L> ReadResult<K, L> takeFromCache() {
62: return ThreadCache.takeFromCache(CACHE_IDX);
63: }
64:
65: /**
66: * Connection, from which data were read.
67: */
68: private Connection<L> connection;
69:
70: /**
71: * message data
72: */
73: private K message;
74:
75: /**
76: * Source address.
77: */
78:
79: private Holder<L> srcAddressHolder;
80:
81: /**
82: * Number of bytes read.
83: */
84: private int readSize;
85:
86: protected ReadResult() {
87: }
88:
89: protected ReadResult(final Connection<L> connection) {
90: this(connection, null, null, 0);
91: }
92:
93: protected ReadResult(final Connection<L> connection, final K message, final L srcAddress, final int readSize) {
94: this.connection = connection;
95: this.message = message;
96: this.srcAddressHolder = Holder.staticHolder(srcAddress);
97: this.readSize = readSize;
98: }
99:
100: /**
101: * Get the {@link Connection} data were read from.
102: *
103: * @return the {@link Connection} data were read from.
104: */
105: @Override
106: public final Connection<L> getConnection() {
107: checkRecycled();
108: return connection;
109: }
110:
111: /**
112: * Get the message, which was read.
113: *
114: * @return the message, which was read.
115: */
116: public final K getMessage() {
117: checkRecycled();
118: return message;
119: }
120:
121: /**
122: * Set the message, which was read.
123: *
124: * @param message the message, which was read.
125: */
126: public final void setMessage(K message) {
127: checkRecycled();
128: this.message = message;
129: }
130:
131: /**
132: * Get the source address, the message was read from.
133: *
134: * @return the source address, the message was read from.
135: */
136: public final L getSrcAddress() {
137: checkRecycled();
138:• return srcAddressHolder != null ? srcAddressHolder.get() : null;
139: }
140:
141: /**
142: * Get the source address, the message was read from.
143: *
144: * @return the source address, the message was read from.
145: */
146: public final Holder<L> getSrcAddressHolder() {
147: checkRecycled();
148: return srcAddressHolder;
149: }
150:
151: /**
152: * Set the source address, the message was read from.
153: *
154: * @param srcAddress the source address, the message was read from.
155: */
156: public final void setSrcAddress(L srcAddress) {
157: checkRecycled();
158: this.srcAddressHolder = Holder.staticHolder(srcAddress);
159: }
160:
161: /**
162: * Set the source address, the message was read from.
163: *
164: * @param srcAddressHolder the source address, the message was read from.
165: */
166: public final void setSrcAddressHolder(Holder<L> srcAddressHolder) {
167: checkRecycled();
168: this.srcAddressHolder = srcAddressHolder;
169: }
170:
171: /**
172: * Get the number of bytes, which were read.
173: *
174: * @return the number of bytes, which were read.
175: */
176: public final int getReadSize() {
177: checkRecycled();
178: return readSize;
179: }
180:
181: /**
182: * Set the number of bytes, which were read.
183: *
184: * @param readSize the number of bytes, which were read.
185: */
186: public final void setReadSize(int readSize) {
187: checkRecycled();
188: this.readSize = readSize;
189: }
190:
191: /**
192: * One method to set all the WriteResult properties.
193: *
194: * @param connection the connection the data was read from
195: * @param message the message which was read
196: * @param srcAddress the source address the message was read from
197: * @param readSize number of bytes which were read
198: */
199: protected void set(final Connection<L> connection, final K message, final L srcAddress, final int readSize) {
200: this.connection = connection;
201: this.message = message;
202: this.srcAddressHolder = Holder.staticHolder(srcAddress);
203: this.readSize = readSize;
204: }
205:
206: protected void reset() {
207: connection = null;
208: message = null;
209: srcAddressHolder = null;
210: readSize = 0;
211: }
212:
213: private void checkRecycled() {
214:• if (Grizzly.isTrackingThreadCache() && isRecycled) {
215: throw new IllegalStateException("ReadResult has been recycled!");
216: }
217: }
218:
219: @Override
220: public void recycle() {
221: reset();
222: isRecycled = true;
223: ThreadCache.putToCache(CACHE_IDX, this);
224: }
225:
226: @Override
227: public Object copy() {
228: return ReadResult.create(getConnection(), getMessage(), getSrcAddress(), getReadSize());
229: }
230: }