Github user shawnfeldman commented on a diff in the pull request:

    https://github.com/apache/incubator-usergrid/pull/255#discussion_r31182808
  
    --- Diff: 
stack/core/src/main/java/org/apache/usergrid/corepersistence/asyncevents/AmazonAsyncEventService.java
 ---
    @@ -0,0 +1,425 @@
    +/*
    + * 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.usergrid.corepersistence.asyncevents;
    +
    +
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +import com.google.common.base.Preconditions;
    +import org.apache.usergrid.corepersistence.CpEntityManager;
    +import org.apache.usergrid.corepersistence.asyncevents.model.*;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import org.apache.usergrid.corepersistence.index.EntityIndexOperation;
    +import org.apache.usergrid.corepersistence.index.IndexProcessorFig;
    +import org.apache.usergrid.corepersistence.index.IndexService;
    +import org.apache.usergrid.persistence.collection.EntityCollectionManager;
    +import 
org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
    +import 
org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
    +import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
    +import org.apache.usergrid.persistence.core.rx.RxTaskScheduler;
    +import org.apache.usergrid.persistence.core.scope.ApplicationScope;
    +import org.apache.usergrid.persistence.graph.Edge;
    +import org.apache.usergrid.persistence.model.entity.Entity;
    +import org.apache.usergrid.persistence.model.entity.Id;
    +import org.apache.usergrid.persistence.queue.QueueManager;
    +import org.apache.usergrid.persistence.queue.QueueManagerFactory;
    +import org.apache.usergrid.persistence.queue.QueueMessage;
    +import org.apache.usergrid.persistence.queue.QueueScope;
    +import org.apache.usergrid.persistence.queue.impl.QueueScopeImpl;
    +
    +import com.codahale.metrics.Counter;
    +import com.codahale.metrics.Gauge;
    +import com.codahale.metrics.Timer;
    +import com.google.inject.Inject;
    +import com.google.inject.Singleton;
    +
    +import rx.Observable;
    +import rx.Subscriber;
    +import rx.Subscription;
    +import rx.schedulers.Schedulers;
    +
    +
    +@Singleton
    +public class AmazonAsyncEventService implements AsyncEventService {
    +
    +
    +    private static final Logger logger = 
LoggerFactory.getLogger(AmazonAsyncEventService.class);
    +    private static final int MAX_TAKE = 10;
    +    private static final String QUEUE_NAME = "es_queue";
    +
    +    private final QueueManager queue;
    +    private final IndexProcessorFig indexProcessorFig;
    +    private final IndexService indexService;
    +    private final EntityCollectionManagerFactory 
entityCollectionManagerFactory;
    +    private final RxTaskScheduler rxTaskScheduler;
    +
    +    private final Timer readTimer;
    +    private final Timer writeTimer;
    +    private final Timer messageProcessingTimer;
    +
    +    private final Object mutex = new Object();
    +
    +    private final Counter indexErrorCounter;
    +    private final AtomicLong counter = new AtomicLong();
    +    private final AtomicLong inFlight = new AtomicLong();
    +
    +    //the actively running subscription
    +    private List<Subscription> subscriptions = new ArrayList<>();
    +
    +
    +    @Inject
    +    public AmazonAsyncEventService(final QueueManagerFactory 
queueManagerFactory,
    +                                   final IndexProcessorFig 
indexProcessorFig,
    +                                   final MetricsFactory metricsFactory,
    +                                   final IndexService indexService,
    +                                   final EntityCollectionManagerFactory 
entityCollectionManagerFactory,
    +                                   final RxTaskScheduler rxTaskScheduler) {
    +
    +        this.indexService = indexService;
    +        this.entityCollectionManagerFactory = 
entityCollectionManagerFactory;
    +        this.rxTaskScheduler = rxTaskScheduler;
    +
    +        final QueueScope queueScope = new QueueScopeImpl(QUEUE_NAME);
    +        this.queue = queueManagerFactory.getQueueManager(queueScope);
    +        this.indexProcessorFig = indexProcessorFig;
    +
    +        this.writeTimer = 
metricsFactory.getTimer(AmazonAsyncEventService.class, "write");
    +        this.readTimer = 
metricsFactory.getTimer(AmazonAsyncEventService.class, "read");
    +        this.messageProcessingTimer = 
metricsFactory.getTimer(AmazonAsyncEventService.class, "message.processing");
    +        this.indexErrorCounter = 
metricsFactory.getCounter(AmazonAsyncEventService.class, "error");
    +
    +
    +        //wire up the gauge of inflight message
    +        metricsFactory.addGauge(AmazonAsyncEventService.class, 
"inflight.meter", new Gauge<Long>() {
    +            @Override
    +            public Long getValue() {
    +                return inFlight.longValue();
    +            }
    +        });
    +
    +        start();
    +    }
    +
    +
    +    /**
    +     * Offer the EntityIdScope to SQS
    +     */
    +    private void offer(final Object operation) {
    +        final Timer.Context timer = this.writeTimer.time();
    +
    +        try {
    +            //signal to SQS
    +            this.queue.sendMessage(operation);
    +        } catch (IOException e) {
    +            throw new RuntimeException("Unable to queue message", e);
    +        } finally {
    +            timer.stop();
    +        }
    +    }
    +
    +
    +    /**
    +     * Take message from SQS
    +     */
    +    public List<QueueMessage> take() {
    --- End diff --
    
    should be Observable<QueueMessage>


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to