reta commented on a change in pull request #660: [CXF-8263] Support SSEs in MP 
Rest Client 2.0
URL: https://github.com/apache/cxf/pull/660#discussion_r410784324
 
 

 ##########
 File path: 
rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/sse/SseSubscription.java
 ##########
 @@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.microprofile.client.sse;
+
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.ws.rs.sse.InboundSseEvent;
+
+import org.apache.cxf.common.util.SystemPropertyAction;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+public class SseSubscription implements Subscription {
+
+    private static final int DEFAULT_BUFFER_SIZE = 
+        
SystemPropertyAction.getInteger("org.apache.cxf.microprofile.client.sse.bufferSize",
 256);
+    private final SsePublisher publisher;
+    private final Subscriber<? super InboundSseEvent> subscriber;
+    private final AtomicLong requested = new AtomicLong();
+    private final AtomicLong delivered = new AtomicLong();
+    private final AtomicBoolean completed = new AtomicBoolean();
+    private final Queue<InboundSseEvent> buffer = new LinkedList<>();
+    private final AtomicInteger bufferSize = new 
AtomicInteger(DEFAULT_BUFFER_SIZE);
+
+    SseSubscription(SsePublisher publisher, Subscriber<? super 
InboundSseEvent> subscriber) {
+        this.publisher = publisher;
+        this.subscriber = subscriber;
+    }
+
+    @Override
+    public void request(long n) {
+        if (n < 1) {
+            throw new IllegalArgumentException("Only postive values are valid 
- passed-in " + n);
+        }
+        requested.addAndGet(n);
+        synchronized (buffer) {
+            InboundSseEvent bufferedEvent = null;
+            while (delivered.get() < requested.get()
+                   && (bufferedEvent = ((LinkedList<InboundSseEvent>) 
buffer).pollFirst()) != null) {
 
 Review comment:
   :+1: would be probably better since there are too many casts ...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to