arjunashok commented on code in PR #139:
URL: https://github.com/apache/cassandra-sidecar/pull/139#discussion_r1852989670


##########
server/src/main/java/org/apache/cassandra/sidecar/job/OperationsJobManager.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.cassandra.sidecar.job;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Singleton;
+import 
org.apache.cassandra.sidecar.common.utils.OperationsJobResult.OperationsJobStatus;
+import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+
+/**
+ * An abstraction of the management and tracking of long-running jobs running 
on the sidecar.
+ */
+@Singleton
+public class OperationsJobManager
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(OperationsJobManager.class);
+
+    private final OperationsJobTracker jobTracker;
+    private final ExecutorPools executorPools;
+
+    /**
+     * Creates a manager instance with a default sized job-tracker.
+     * @param executorPools
+     */
+    @Inject
+    public OperationsJobManager(ExecutorPools executorPools, 
OperationsJobTracker jobTracker)
+    {
+        this.executorPools = executorPools;
+        this.jobTracker = jobTracker;
+    }
+
+    /**
+     * Fetches the inflight jobs being tracked on the sidecar
+     * @return instances of the jobs that are in pending or running states
+     */
+    public List<OperationsJob> allInflightJobs()
+    {
+        return jobTracker.getJobsView().values()
+                         .stream()
+                         .filter(j -> j.status() == 
OperationsJobStatus.Pending || j.status() == OperationsJobStatus.Running)
+                         .collect(Collectors.toList());
+    }
+
+    /**
+     * Fetch the job using its UUID
+     * @param jobId identifier of the job
+     * @return instance of the job or null
+     */
+    public OperationsJob getJobIfExists(UUID jobId)
+    {
+        return jobTracker.get(jobId);

Review Comment:
   `allInflightJobs` iterates over all entries, so doing this without holding 
locks is beneficial to not affect other actions. 
   
   `getJobIfExists` on the other hand is a point lookup.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to