|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
1 | 4 | package com.microsoft.azure.servicebus; |
2 | 5 |
|
3 | | -import java.io.IOException; |
4 | 6 | import java.time.Duration; |
5 | 7 | import java.time.Instant; |
6 | 8 | import java.util.Collection; |
7 | 9 | import java.util.Map; |
8 | 10 | import java.util.UUID; |
9 | 11 | import java.util.concurrent.CompletableFuture; |
10 | | -import java.util.concurrent.ExecutionException; |
11 | 12 |
|
12 | | -import com.microsoft.azure.servicebus.primitives.CoreMessageReceiver; |
13 | 13 | import com.microsoft.azure.servicebus.primitives.MessagingFactory; |
14 | 14 | import com.microsoft.azure.servicebus.primitives.ServiceBusException; |
15 | 15 |
|
16 | | -final class BrowsableMessageSession extends MessageSession |
17 | | -{ |
18 | | - private static final String INVALID_OPERATION_ERROR_MESSAGE = "Unsupported operation on a browse only session."; |
19 | | - |
20 | | - BrowsableMessageSession(String sessionId, MessagingFactory messagingFactory, String entityPath) |
21 | | - { |
22 | | - super(messagingFactory, entityPath, sessionId, ReceiveMode.PeekLock); |
| 16 | +/** |
| 17 | + * A session object that can only be used to browse messages and state of a server side session. It cannot be used to receive messages from the service or to set state of the session. |
| 18 | + */ |
| 19 | +final class BrowsableMessageSession extends MessageSession { |
| 20 | + private static final String INVALID_OPERATION_ERROR_MESSAGE = "Unsupported operation on a browse only session."; |
| 21 | + |
| 22 | + BrowsableMessageSession(String sessionId, MessagingFactory messagingFactory, String entityPath) { |
| 23 | + super(messagingFactory, entityPath, sessionId, ReceiveMode.PEEKLOCK); |
23 | 24 | // try { |
24 | 25 | // this.initializeAsync().get(); |
25 | 26 | // } catch (InterruptedException | ExecutionException e) { |
26 | 27 | // |
27 | 28 | // } |
28 | | - } |
29 | | - |
30 | | - @Override |
31 | | - protected boolean isBrowsableSession() |
32 | | - { |
33 | | - return true; |
34 | | - } |
35 | | - |
36 | | - @Override |
37 | | - public String getSessionId() |
38 | | - { |
39 | | - return this.getRequestedSessionId(); |
40 | | - } |
41 | | - |
42 | | - @Override |
43 | | - public Instant getLockedUntilUtc() { |
44 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
45 | | - } |
46 | | - |
47 | | - @Override |
48 | | - public int getPrefetchCount() |
49 | | - { |
50 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
51 | | - } |
52 | | - |
53 | | - @Override |
54 | | - public void setPrefetchCount(int prefetchCount) throws ServiceBusException |
55 | | - { |
56 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
57 | | - } |
58 | | - |
59 | | - @Override |
60 | | - public CompletableFuture<Void> setStateAsync(byte[] sessionState) { |
61 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
62 | | - } |
63 | | - |
64 | | - @Override |
65 | | - public CompletableFuture<Void> renewLockAsync() { |
66 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
67 | | - } |
68 | | - |
69 | | - @Override |
70 | | - public ReceiveMode getReceiveMode() { |
71 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
72 | | - } |
73 | | - |
74 | | - @Override |
75 | | - public CompletableFuture<Void> abandonAsync(UUID lockToken, Map<String, Object> propertiesToModify) |
76 | | - { |
77 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
78 | | - } |
79 | | - |
80 | | - @Override |
81 | | - public CompletableFuture<Void> completeAsync(UUID lockToken) |
82 | | - { |
83 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
84 | | - } |
85 | | - |
86 | | - @Override |
87 | | - public CompletableFuture<Void> completeBatchAsync(Collection<? extends IMessage> messages) { |
88 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
89 | | - } |
90 | | - |
91 | | - @Override |
92 | | - public CompletableFuture<Void> deadLetterAsync(UUID lockToken, String deadLetterReason, String deadLetterErrorDescription, Map<String, Object> propertiesToModify) |
93 | | - { |
94 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
95 | | - } |
96 | | - |
97 | | - @Override |
98 | | - public CompletableFuture<Void> deferAsync(UUID lockToken, Map<String, Object> propertiesToModify) |
99 | | - { |
100 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
101 | | - } |
102 | | - |
103 | | - @Override |
104 | | - public CompletableFuture<IMessage> receiveAsync() |
105 | | - { |
106 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
107 | | - } |
108 | | - |
109 | | - @Override |
110 | | - public CompletableFuture<IMessage> receiveAsync(Duration serverWaitTime) |
111 | | - { |
112 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
113 | | - } |
114 | | - |
115 | | - @Override |
116 | | - public CompletableFuture<IMessage> receiveAsync(long sequenceNumber) |
117 | | - { |
118 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
119 | | - } |
120 | | - |
121 | | - @Override |
122 | | - public CompletableFuture<Collection<IMessage>> receiveBatchAsync(int maxMessageCount) |
123 | | - { |
124 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
125 | | - } |
126 | | - |
127 | | - @Override |
128 | | - public CompletableFuture<Collection<IMessage>> receiveBatchAsync(int maxMessageCount, Duration serverWaitTime) |
129 | | - { |
130 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
131 | | - } |
132 | | - |
133 | | - @Override |
134 | | - public CompletableFuture<Collection<IMessage>> receiveBatchAsync(Collection<Long> sequenceNumbers) |
135 | | - { |
136 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
137 | | - } |
138 | | - |
139 | | - @Override |
140 | | - public CompletableFuture<Instant> renewMessageLockAsync(IMessage message) |
141 | | - { |
142 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
143 | | - } |
144 | | - |
145 | | - @Override |
146 | | - public CompletableFuture<Collection<Instant>> renewMessageLockBatchAsync(Collection<? extends IMessage> messages) |
147 | | - { |
148 | | - throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
149 | | - } |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + protected boolean isBrowsableSession() { |
| 33 | + return true; |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public String getSessionId() { |
| 38 | + return this.getRequestedSessionId(); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public Instant getLockedUntilUtc() { |
| 43 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public int getPrefetchCount() { |
| 48 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void setPrefetchCount(int prefetchCount) throws ServiceBusException { |
| 53 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public CompletableFuture<Void> setStateAsync(byte[] sessionState) { |
| 58 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public CompletableFuture<Void> renewSessionLockAsync() { |
| 63 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public ReceiveMode getReceiveMode() { |
| 68 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public CompletableFuture<Void> abandonAsync(UUID lockToken, Map<String, Object> propertiesToModify) { |
| 73 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public CompletableFuture<Void> completeAsync(UUID lockToken) { |
| 78 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public CompletableFuture<Void> completeBatchAsync(Collection<? extends IMessage> messages) { |
| 83 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public CompletableFuture<Void> deadLetterAsync(UUID lockToken, String deadLetterReason, String deadLetterErrorDescription, Map<String, Object> propertiesToModify) { |
| 88 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public CompletableFuture<Void> deferAsync(UUID lockToken, Map<String, Object> propertiesToModify) { |
| 93 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public CompletableFuture<IMessage> receiveAsync() { |
| 98 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public CompletableFuture<IMessage> receiveAsync(Duration serverWaitTime) { |
| 103 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public CompletableFuture<IMessage> receiveDeferredMessageAsync(long sequenceNumber) { |
| 108 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public CompletableFuture<Collection<IMessage>> receiveBatchAsync(int maxMessageCount) { |
| 113 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + public CompletableFuture<Collection<IMessage>> receiveBatchAsync(int maxMessageCount, Duration serverWaitTime) { |
| 118 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public CompletableFuture<Collection<IMessage>> receiveDeferredMessageBatchAsync(Collection<Long> sequenceNumbers) { |
| 123 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public CompletableFuture<Instant> renewMessageLockAsync(IMessage message) { |
| 128 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public CompletableFuture<Collection<Instant>> renewMessageLockBatchAsync(Collection<? extends IMessage> messages) { |
| 133 | + throw new UnsupportedOperationException(INVALID_OPERATION_ERROR_MESSAGE); |
| 134 | + } |
150 | 135 | } |
0 commit comments