Example usage for org.apache.commons.lang.mutable MutableLong MutableLong

List of usage examples for org.apache.commons.lang.mutable MutableLong MutableLong

Introduction

In this page you can find the example usage for org.apache.commons.lang.mutable MutableLong MutableLong.

Prototype

public MutableLong(Number value) 

Source Link

Document

Constructs a new MutableLong with the specified value.

Usage

From source file:com.jivesoftware.os.filer.queue.guaranteed.delivery.FileQueueBackGuaranteedDeliveryFactory.java

/**
 *
 * @param serviceConfig/*from   w  ww. ja  v  a2  s.c  om*/
 * @param deliveryCallback
 * @return
 * @throws IOException
 */
public static GuaranteedDeliveryService createService(
        FileQueueBackGuaranteedDeliveryServiceConfig serviceConfig, DeliveryCallback deliveryCallback)
        throws IOException {

    final MutableLong undelivered = new MutableLong(0);
    final MutableLong delivered = new MutableLong(0);
    final FileQueueImpl queue = new FileQueueImpl(serviceConfig.getPathToQueueFiles(),
            serviceConfig.getQueueName(), serviceConfig.getTakableWhenCreationTimestampIsOlderThanXMillis(),
            serviceConfig.getTakableWhenLastAppendedIsOlderThanXMillis(),
            serviceConfig.getTakableWhenLargerThanXEntries(), serviceConfig.getMaxPageSizeInBytes(),
            serviceConfig.getPushbackAtEnqueuedSize(), serviceConfig.isDeleteOnExit(), undelivered,
            serviceConfig.isTakeFullQueuesOnly());

    final GuaranteedDeliveryServiceStatus status = new GuaranteedDeliveryServiceStatus() {
        @Override
        public long undelivered() {
            return undelivered.longValue();
        }

        @Override
        public long delivered() {
            return delivered.longValue();
        }
    };

    final QueueProcessorPool processorPool = new QueueProcessorPool(queue, serviceConfig.getNumberOfConsumers(),
            serviceConfig.getQueueProcessorConfig(), delivered, deliveryCallback);

    GuaranteedDeliveryService service = new GuaranteedDeliveryService() {
        private final AtomicBoolean running = new AtomicBoolean(false);

        @Override
        public void add(List<byte[]> add) throws DeliveryServiceException {
            if (running.compareAndSet(false, true)) {
                processorPool.start();
            }

            if (add == null) {
                return;
            }
            for (int i = 0; i < add.size(); i++) {
                byte[] value = add.get(i);
                if (value == null) {
                    continue;
                }
                try {
                    queue.add(PhasedQueueConstants.ENQUEUED, System.currentTimeMillis(), value);
                } catch (Exception ex) {
                    throw new DeliveryServiceException(add, "failed tp deliver the following items", ex);
                }
            }
        }

        @Override
        public GuaranteedDeliveryServiceStatus getStatus() {
            return status;
        }

        @Override
        public void close() {
            if (running.compareAndSet(true, false)) {
                processorPool.stop();
            }
        }
    };

    return service;
}

From source file:com.linkedin.pinot.core.data.readers.BaseRecordReader.java

protected void initNullCounters(Schema schema) {
    _nullCountMap = new HashMap<String, MutableLong>(schema.getAllFieldSpecs().size());
    for (String fieldName : schema.getColumnNames()) {
        _nullCountMap.put(fieldName, new MutableLong(0));
    }/*from  ww w  . j  a v  a  2  s  .  c o m*/
}

From source file:com.datatorrent.contrib.redis.NumberSummation.java

protected Number convertToNumber(Object o) {
    if (o == null) {
        return null;
    } else if (o instanceof MutableDouble || o instanceof MutableLong) {
        return (Number) o;
    } else if (o instanceof Double || o instanceof Float) {
        return new MutableDouble((Number) o);
    } else if (o instanceof Number) {
        return new MutableLong((Number) o);
    } else {/*w w  w.j  av a 2 s .  c o m*/
        return new MutableDouble(o.toString());
    }
}

From source file:com.ebay.erl.mobius.core.mapred.CounterUpdateThread.java

public void updateCounter(String groupName, String counterName, long newCounts) {
    Counter counter = this.getCounterByName(groupName, counterName);
    synchronized (this.counts) {
        MutableLong count;//from  ww  w. j a  v  a  2s.  com
        if ((count = this.counts.get(counter)) == null) {
            count = new MutableLong(0L);
            this.counts.put(counter, count);
        }
        count.setValue(newCounts);
    }
}

From source file:com.datatorrent.lib.io.fs.AbstractSingleFileOutputOperatorTest.java

private CheckPointOutputOperator checkpoint(AbstractSingleFileOutputOperator<Integer> writer) {
    CheckPointOutputOperator checkPointWriter = new CheckPointOutputOperator();
    checkPointWriter.counts = Maps.newHashMap();

    for (String keys : writer.counts.keySet()) {
        checkPointWriter.counts.put(keys, new MutableLong(writer.counts.get(keys).longValue()));
    }/*from w  w w. j  a  v a 2 s  .  c  om*/

    checkPointWriter.endOffsets = Maps.newHashMap();

    for (String keys : writer.endOffsets.keySet()) {
        checkPointWriter.endOffsets.put(keys, new MutableLong(writer.endOffsets.get(keys).longValue()));
    }

    checkPointWriter.openPart = Maps.newHashMap();

    for (String keys : writer.openPart.keySet()) {
        checkPointWriter.openPart.put(keys, new MutableInt(writer.openPart.get(keys).intValue()));
    }

    checkPointWriter.filePath = writer.filePath;
    checkPointWriter.maxOpenFiles = writer.maxOpenFiles;
    checkPointWriter.replication = writer.replication;
    checkPointWriter.totalBytesWritten = writer.totalBytesWritten;
    checkPointWriter.maxLength = writer.maxLength;
    checkPointWriter.rollingFile = writer.rollingFile;
    checkPointWriter.outputFileName = writer.outputFileName;

    return checkPointWriter;
}

From source file:eu.eubrazilcc.lvl.service.rest.NotificationResource.java

@GET
@Produces(APPLICATION_JSON)//  w  w  w . j ava 2  s  .  co  m
public Notifications getNotifications(final @QueryParam("page") @DefaultValue("0") int page,
        final @QueryParam("per_page") @DefaultValue("100") int per_page,
        final @QueryParam("q") @DefaultValue("") String q,
        final @QueryParam("sort") @DefaultValue("") String sort,
        final @QueryParam("order") @DefaultValue("asc") String order, final @Context UriInfo uriInfo,
        final @Context HttpServletRequest request, final @Context HttpHeaders headers) {
    OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
            .requiresPermissions("notifications:*:public:*:view");
    final Notifications paginable = Notifications.start().page(page).perPage(per_page).sort(sort).order(order)
            .query(q).build();
    // get notifications from database
    final MutableLong count = new MutableLong(0l);
    final ImmutableMap<String, String> filter = parseQuery(q);
    final Sorting sorting = parseSorting(sort, order);
    final List<Notification> notifications = NOTIFICATION_DAO.list(paginable.getPageFirstEntry(), per_page,
            filter, sorting, null, count);
    paginable.setElements(notifications);
    // set total count and return to the caller
    final int totalEntries = ((Long) count.getValue()).intValue();
    paginable.setTotalCount(totalEntries);
    return paginable;
}

From source file:eu.eubrazilcc.lvl.storage.AuthCodeCollectionTest.java

@Test
public void test() {
    System.out.println("AuthCodeCollectionTest.test()");
    try {/*  w ww. j  ava  2 s .c o  m*/
        // insert
        final AuthCode authCode = AuthCode.builder().code("1234567890abcdEFGhiJKlMnOpqrstUVWxyZ")
                .issuedAt(System.currentTimeMillis() / 1000l).expiresIn(23l).build();
        AUTH_CODE_DAO.insert(authCode);

        // find
        AuthCode authCode2 = AUTH_CODE_DAO.find(authCode.getCode());
        assertThat("authorization code is not null", authCode2, notNullValue());
        assertThat("authorization code coincides with original", authCode2, equalTo(authCode));
        System.out.println(authCode2.toString());

        // update
        authCode.setExpiresIn(3600l);
        AUTH_CODE_DAO.update(authCode);

        // find after update
        authCode2 = AUTH_CODE_DAO.find(authCode.getCode());
        assertThat("authorization code is not null", authCode2, notNullValue());
        assertThat("authorization code coincides with original", authCode2, equalTo(authCode));
        System.out.println(authCode2.toString());

        // check validity
        final boolean validity = AUTH_CODE_DAO.isValid(authCode.getCode());
        assertThat("authorization code is valid", validity);

        // remove
        AUTH_CODE_DAO.delete(authCode.getCode());
        final long numRecords = AUTH_CODE_DAO.count();
        assertThat("number of authorization codes stored in the database coincides with expected", numRecords,
                equalTo(0l));

        // pagination
        final List<String> ids = newArrayList();
        for (int i = 0; i < 11; i++) {
            final AuthCode authCode3 = AuthCode.builder().code(Integer.toString(i)).build();
            ids.add(authCode3.getCode());
            AUTH_CODE_DAO.insert(authCode3);
        }
        final int size = 3;
        int start = 0;
        List<AuthCode> authCodes = null;
        final MutableLong count = new MutableLong(0l);
        do {
            authCodes = AUTH_CODE_DAO.list(start, size, null, null, null, count);
            if (authCodes.size() != 0) {
                System.out.println("Paging: first item " + start + ", showing " + authCodes.size() + " of "
                        + count.getValue() + " items");
            }
            start += authCodes.size();
        } while (!authCodes.isEmpty());
        for (final String id2 : ids) {
            AUTH_CODE_DAO.delete(id2);
        }
        AUTH_CODE_DAO.stats(System.out);
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail("AuthCodeCollectionTest.test() failed: " + e.getMessage());
    } finally {
        System.out.println("AuthCodeCollectionTest.test() has finished");
    }
}

From source file:eu.eubrazilcc.lvl.oauth2.rest.IdentityProvider.java

@GET
@Produces(MediaType.APPLICATION_JSON)/*  w w w. jav  a  2  s. co m*/
public Users getUsers(final @QueryParam("page") @DefaultValue("0") int page,
        final @QueryParam("per_page") @DefaultValue("10") int per_page,
        final @QueryParam("plain") @DefaultValue("false") boolean plain, final @Context UriInfo uriInfo,
        final @Context HttpServletRequest request, final @Context HttpHeaders headers) {
    if (plain) {
        OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
                .requiresPermissions("users:*:*:*:view");
    } else {
        OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
                .requiresPermissions("users:active:profile:*:view");
    }
    final Users paginable = Users.start().page(page).perPage(per_page).plain(plain).build();
    // get users from database
    final MutableLong count = new MutableLong(0l);
    final List<ResourceOwner> owners = RESOURCE_OWNER_DAO.useGravatar(true).list(paginable.getPageFirstEntry(),
            per_page, null, null, null, count);
    paginable.setElements(
            from(owners).transform(UserAnonymizer.start(plain ? NONE : HARD)).filter(notNull()).toList());
    // set total count and return to the caller
    final int totalEntries = ((Long) count.getValue()).intValue();
    paginable.setTotalCount(totalEntries);
    return paginable;
}

From source file:eu.eubrazilcc.lvl.storage.WorkflowRunCollectionTest.java

@Test
public void test() {
    System.out.println("WorkflowRunCollectionTest.test()");
    try {/*w  w w. j  a v  a 2 s .co m*/
        // insert
        final WorkflowRun run = WorkflowRun.builder().id("ABCD123").workflowId("980TYHN1").invocationId("1209")
                .parameters(WorkflowParameters.builder().parameter("var1", "1", null, null)
                        .parameter("var2", "2", null, null).build())
                .submitter("submitter").submitted(new Date()).build();
        WORKFLOW_RUN_DAO.insert(run);

        // find
        WorkflowRun run2 = WORKFLOW_RUN_DAO.find(run.getId());
        assertThat("workflow run is not null", run2, notNullValue());
        assertThat("workflow run coincides with original", run2, equalTo(run));
        System.out.println(run2.toString());

        // update
        run.setSubmitter("submitter2");
        WORKFLOW_RUN_DAO.update(run);

        // find after update
        run2 = WORKFLOW_RUN_DAO.find(run.getId());
        assertThat("workflow run is not null", run2, notNullValue());
        assertThat("workflow run coincides with original", run2, equalTo(run));
        System.out.println(run2.toString());

        // list all by submitter
        List<WorkflowRun> runs = WORKFLOW_RUN_DAO.findAll(run.getSubmitter());
        assertThat("workflow runs are not null", runs, notNullValue());
        assertThat("workflow runs are not empty", !runs.isEmpty(), equalTo(true));
        assertThat("number of workflow runs coincides with expected", runs.size(), equalTo(1));
        assertThat("workflow runs coincide with original", runs.get(0), equalTo(run));

        // remove
        WORKFLOW_RUN_DAO.delete(run.getId());
        final long numRecords = WORKFLOW_RUN_DAO.count();
        assertThat("number of workflow runs stored in the database coincides with expected", numRecords,
                equalTo(0l));

        // pagination
        final List<String> ids = newArrayList();
        for (int i = 0; i < 11; i++) {
            final WorkflowRun run3 = WorkflowRun.builder().id(Integer.toString(i)).build();
            ids.add(run3.getId());
            WORKFLOW_RUN_DAO.insert(run3);
        }
        final int size = 3;
        int start = 0;
        runs = null;
        final MutableLong count = new MutableLong(0l);
        do {
            runs = WORKFLOW_RUN_DAO.list(start, size, null, null, null, count);
            if (runs.size() != 0) {
                System.out.println("Paging: first item " + start + ", showing " + runs.size() + " of "
                        + count.getValue() + " items");
            }
            start += runs.size();
        } while (!runs.isEmpty());
        for (final String id2 : ids) {
            WORKFLOW_RUN_DAO.delete(id2);
        }
        WORKFLOW_RUN_DAO.stats(System.out);

    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail("WorkflowRunCollectionTest.test() failed: " + e.getMessage());
    } finally {
        System.out.println("WorkflowRunCollectionTest.test() has finished");
    }
}

From source file:eu.eubrazilcc.lvl.service.rest.LvlInstanceResource.java

@GET
@Produces(APPLICATION_JSON)//from w  w  w .j a  v  a2s  .c o m
public LvlInstances getLvlInstances(final @QueryParam("page") @DefaultValue("0") int page,
        final @QueryParam("per_page") @DefaultValue("100") int per_page,
        final @QueryParam("q") @DefaultValue("") String q,
        final @QueryParam("sort") @DefaultValue("") String sort,
        final @QueryParam("order") @DefaultValue("asc") String order, final @Context UriInfo uriInfo,
        final @Context HttpServletRequest request, final @Context HttpHeaders headers) {
    final LvlInstances paginable = LvlInstances.start().page(page).perPage(per_page).sort(sort).order(order)
            .query(q).build();
    // get instances from database
    final MutableLong count = new MutableLong(0l);
    final ImmutableMap<String, String> filter = parseQuery(q);
    final Sorting sorting = parseSorting(sort, order);
    final List<LvlInstance> instances = INSTANCE_DAO.list(paginable.getPageFirstEntry(), per_page, filter,
            sorting, null, count);
    paginable.setElements(instances);
    // set total count and return to the caller
    final int totalEntries = ((Long) count.getValue()).intValue();
    paginable.setTotalCount(totalEntries);
    return paginable;
}