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() 

Source Link

Document

Constructs a new MutableLong with the default value of zero.

Usage

From source file:com.datatorrent.contrib.hive.HiveOperator.java

@Override
public void setup(OperatorContext context) {
    try {/*www  . j  a v a2s .c o m*/
        fs = getHDFSInstance();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }

    this.context = context;
    lastTimeStamp = System.currentTimeMillis();

    fileCounters.setCounter(Counters.TOTAL_BYTES_WRITTEN, new MutableLong());
    fileCounters.setCounter(Counters.TOTAL_TIME_ELAPSED, new MutableLong());
    super.setup(context);
}

From source file:com.datatorrent.lib.bucket.AbstractTimeBasedBucketManager.java

@Override
public void setBucketCounters(@Nonnull BasicCounters<MutableLong> bucketCounters) {
    super.setBucketCounters(bucketCounters);
    bucketCounters.setCounter(CounterKeys.LOW, new MutableLong());
    bucketCounters.setCounter(CounterKeys.HIGH, new MutableLong());
    bucketCounters.setCounter(CounterKeys.IGNORED_EVENTS, new MutableLong());
}

From source file:de.bbe_consulting.mavento.MagentoInfoMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    initMojo();//from  www.j  av a  2 s.  co  m
    getLog().info("Scanning: " + magentoPath);
    getLog().info("");
    if (mVersion != null) {
        getLog().info("Version: Magento " + mVersion.toString());
    }

    // parse sql properties from local.xml
    final Path localXmlPath = Paths.get(magentoPath + "/app/etc/local.xml");
    Document localXml = null;
    if (Files.exists(localXmlPath)) {
        localXml = MagentoXmlUtil.readXmlFile(localXmlPath.toAbsolutePath().toString());
    } else {
        throw new MojoExecutionException(
                "Could not read or parse /app/etc/local.xml." + " Use -DmagentoPath= to set Magento dir.");
    }
    final Map<String, String> dbSettings = MagentoXmlUtil.getDbValues(localXml);
    final String jdbcUrl = MagentoSqlUtil.getJdbcUrl(dbSettings.get("host"), dbSettings.get("port"),
            dbSettings.get("dbname"));

    // fetch installdate
    final String magentoInstallDate = MagentoXmlUtil.getMagentoInstallData(localXml);
    getLog().info("Installed: " + magentoInstallDate);
    getLog().info("");

    // read baseUrl
    MagentoCoreConfig baseUrl = null;
    try {
        baseUrl = new MagentoCoreConfig("web/unsecure/base_url");
    } catch (Exception e) {
        throw new MojoExecutionException("Error creating config entry. " + e.getMessage(), e);
    }

    String sqlError = SQL_CONNECTION_VALID;
    try {
        baseUrl = MagentoSqlUtil.getCoreConfigData(baseUrl, dbSettings.get("user"), dbSettings.get("password"),
                jdbcUrl, getLog());
        getLog().info("URL: " + baseUrl.getValue());
        getLog().info("");
    } catch (MojoExecutionException e) {
        sqlError = e.getMessage();
    }

    getLog().info("Database: " + dbSettings.get("dbname") + " via " + dbSettings.get("user") + "@"
            + dbSettings.get("host") + ":" + dbSettings.get("port"));
    getLog().info("Connection: " + sqlError);
    getLog().info("");

    if (!skipSize) {
        MutableLong rootSizeTotal = new MutableLong();
        try {
            FileSizeVisitor fs = new FileSizeVisitor(rootSizeTotal);
            Files.walkFileTree(Paths.get(magentoPath), fs);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        getLog().info(
                "Magento files total: " + String.format("%,8d", rootSizeTotal.toLong()).trim() + " bytes");
        if (SQL_CONNECTION_VALID.equals(sqlError)) {
            try {
                final Map<String, Integer> dbDetails = MagentoSqlUtil.getDbSize(dbSettings.get("dbname"),
                        dbSettings.get("user"), dbSettings.get("password"), jdbcUrl, getLog());
                final List<MysqlTable> logTableDetails = MagentoSqlUtil.getLogTablesSize(
                        dbSettings.get("dbname"), dbSettings.get("user"), dbSettings.get("password"), jdbcUrl,
                        getLog());
                getLog().info("Database total: " + String.format("%,8d", dbDetails.get("totalRows")).trim()
                        + " entries / " + String.format("%,8d", dbDetails.get("totalSize")).trim() + "mb");
                int logSizeTotal = 0;
                int logRowsTotal = 0;
                for (MysqlTable t : logTableDetails) {
                    logSizeTotal += t.getTableSizeInMb();
                    logRowsTotal += t.getTableRows();
                    if (showDetails) {
                        getLog().info(" " + t.getTableName() + ": " + t.getFormatedTableEntries()
                                + " entries / " + t.getFormatedTableSizeInMb() + "mb");
                    }
                }
                getLog().info("Log tables total: " + String.format("%,8d", logRowsTotal).trim() + " entries / "
                        + String.format("%,8d", logSizeTotal).trim() + "mb");
            } catch (MojoExecutionException e) {
                getLog().info("Error: " + e.getMessage());
            }
        }
        getLog().info("");
    }
    // parse modules
    final Path modulesXmlPath = Paths.get(magentoPath + "/app/etc/modules");
    if (!Files.exists(modulesXmlPath)) {
        throw new MojoExecutionException("Could not find /app/etc/modules directory.");
    }

    DirectoryStream<Path> files = null;
    final ArrayList<MagentoModule> localModules = new ArrayList<MagentoModule>();
    final ArrayList<MagentoModule> communityModules = new ArrayList<MagentoModule>();
    try {
        files = Files.newDirectoryStream(modulesXmlPath);
        for (Path path : files) {
            if (!path.getFileName().toString().startsWith("Mage")) {
                MagentoModule m = new MagentoModule(path);
                if (m.getCodePool().equals("local")) {
                    localModules.add(m);
                } else {
                    communityModules.add(m);
                }
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Could not read modules directory. " + e.getMessage(), e);
    } finally {
        try {
            files.close();
        } catch (IOException e) {
            throw new MojoExecutionException("Error closing directory stream. " + e.getMessage(), e);
        }
    }

    // print module sorted module list
    final MagentoModuleComperator mmc = new MagentoModuleComperator();
    Collections.sort(localModules, mmc);
    Collections.sort(communityModules, mmc);

    getLog().info("Installed modules in..");

    getLog().info("..local: ");
    for (MagentoModule m : localModules) {
        getLog().info(m.getNamespace() + "_" + m.getName() + " version: " + m.getVersion() + " active: "
                + m.isActive());
    }
    if (localModules.size() == 0) {
        getLog().info("--none--");
    }
    getLog().info("");

    getLog().info("..community: ");
    for (MagentoModule m : communityModules) {
        getLog().info(m.getNamespace() + "_" + m.getName() + " version: " + m.getVersion() + " active: "
                + m.isActive());
    }
    if (communityModules.size() == 0) {
        getLog().info("--none--");
    }
    getLog().info("");

    // check local overlays for content
    getLog().info("Overlay status..");
    int fileCount = -1;
    final File localMage = new File(magentoPath + "/app/code/local/Mage");
    if (localMage.exists()) {
        fileCount = localMage.list().length;
        if (fileCount > 0) {
            getLog().info("local/Mage: " + localMage.list().length + " file(s)");
        }
    }
    final File localVarien = new File(magentoPath + "/app/code/local/Varien");

    if (localVarien.exists()) {
        fileCount = localVarien.list().length;
        if (fileCount > 0) {
            getLog().info("local/Varien: " + localVarien.list().length + " file(s)");
        }
    }

    if (fileCount == -1) {
        getLog().info("..not in use.");
    }

}

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

@Override
public void setup(Context.OperatorContext context) {
    Preconditions.checkArgument(!scanner.files.isEmpty(), "empty files");
    Preconditions.checkArgument(blockSize == null || blockSize > 0, "invalid block size");

    operatorId = context.getId();/*w  w  w.j a  v a2  s  .  c  o  m*/
    this.context = context;

    fileCounters.setCounter(Counters.PROCESSED_FILES, new MutableLong());
    windowDataManager.setup(context);

    try {
        fs = scanner.getFSInstance();
    } catch (IOException e) {
        throw new RuntimeException("creating fs", e);
    }

    if (blockSize == null) {
        blockSize = fs.getDefaultBlockSize(new Path(scanner.files.iterator().next()));
    }

    if (context.getValue(Context.OperatorContext.ACTIVATION_WINDOW_ID) < windowDataManager
            .getLargestCompletedWindow()) {
        blockMetadataIterator = null;
    } else {
        //don't setup scanner while recovery
        scanner.setup(context);
    }
}

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

@Override
public void setup(Context.OperatorContext context) {
    operatorId = context.getId();/*from  ww  w. java2s .  c  om*/
    LOG.debug("{}: partition keys {} mask {}", operatorId, partitionKeys, partitionMask);

    this.context = context;
    counters.setCounter(ReaderCounterKeys.BLOCKS, new MutableLong());
    counters.setCounter(ReaderCounterKeys.RECORDS, new MutableLong());
    counters.setCounter(ReaderCounterKeys.BYTES, new MutableLong());
    counters.setCounter(ReaderCounterKeys.TIME, new MutableLong());
    counters.setCounter(ReaderCounterKeys.BACKLOG, new MutableLong());
    sleepTimeMillis = context.getValue(Context.OperatorContext.SPIN_MILLIS);
    configuration = new Configuration();
    try {
        fs = getFSInstance();
    } catch (IOException e) {
        throw new RuntimeException("creating fs", e);
    }
}

From source file:com.datatorrent.lib.io.block.AbstractBlockReader.java

@Override
public void setup(Context.OperatorContext context) {
    operatorId = context.getId();/*from ww w .  ja  va 2 s.  com*/
    LOG.debug("{}: partition keys {} mask {}", operatorId, partitionKeys, partitionMask);

    this.context = context;
    counters.setCounter(ReaderCounterKeys.BLOCKS, new MutableLong());
    counters.setCounter(ReaderCounterKeys.RECORDS, new MutableLong());
    counters.setCounter(ReaderCounterKeys.BYTES, new MutableLong());
    counters.setCounter(ReaderCounterKeys.TIME, new MutableLong());
    sleepTimeMillis = context.getValue(Context.OperatorContext.SPIN_MILLIS);
}

From source file:com.jivesoftware.os.upena.amza.transport.http.replication.endpoints.UpenaAmzaReplicationRestEndpoints.java

@POST
@Consumes("application/json")
@Path("/changes/take")
public Response take(final RowUpdates rowUpdates) {
    try {/*w w w . j a v a  2s.c o  m*/

        final BinaryRowMarshaller rowMarshaller = new BinaryRowMarshaller();
        final List<byte[]> rows = new ArrayList<>();
        final MutableLong highestTransactionId = new MutableLong();
        amzaInstance.takeRowUpdates(rowUpdates.getTableName(), rowUpdates.getHighestTransactionId(),
                new RowScan() {
                    @Override
                    public boolean row(long orderId, RowIndexKey key, RowIndexValue value) throws Exception {
                        rows.add(rowMarshaller.toRow(orderId, key, value));
                        if (orderId > highestTransactionId.longValue()) {
                            highestTransactionId.setValue(orderId);
                        }
                        return true;
                    }
                });

        return ResponseHelper.INSTANCE.jsonResponse(
                new RowUpdates(highestTransactionId.longValue(), rowUpdates.getTableName(), rows));
    } catch (Exception x) {
        LOG.warn("Failed to apply changeset: " + rowUpdates, x);
        return ResponseHelper.INSTANCE.errorResponse("Failed to changeset " + rowUpdates, x);
    }
}

From source file:com.palantir.atlasdb.schema.TableMigratorTest.java

@Test
public void testMigrationToDifferentKvs() {
    final String tableName = "table";
    final String namespacedTableName = "namespace." + tableName;
    TableDefinition definition = new TableDefinition() {
        {//from   ww w.  jav a  2s  .c o  m
            rowName();
            rowComponent("r", ValueType.BLOB);
            columns();
            column("c", "c", ValueType.BLOB);
        }
    };
    SimpleSchemaUpdater updater = SimpleSchemaUpdaterImpl.create(keyValueService, Namespace.DEFAULT_NAMESPACE);
    updater.addTable(tableName, definition);
    int maxValueSize = definition.getMaxValueSize();
    keyValueService.createTable(namespacedTableName, maxValueSize);
    keyValueService.putMetadataForTable(namespacedTableName, definition.toTableMetadata().persistToBytes());

    TableMappingService tableMap = StaticTableMappingService.create(keyValueService);
    final String shortTableName = tableMap
            .getShortTableName(TableReference.create(Namespace.create("namespace"), tableName));

    final Cell theCell = Cell.create(PtBytes.toBytes("r1"), PtBytes.toBytes("c"));
    final byte[] theValue = PtBytes.toBytes("v1");
    txManager.runTaskWithRetry(new TransactionTask<Void, RuntimeException>() {
        @Override
        public Void execute(Transaction t) {
            Map<Cell, byte[]> values = ImmutableMap.of(theCell, theValue);
            t.put("default." + tableName, values);
            t.put(namespacedTableName, values);
            return null;
        }
    });

    // migration doesn't use namespace mapping
    final InMemoryKeyValueService kvs2 = new InMemoryKeyValueService(false);
    final ConflictDetectionManager cdm2 = ConflictDetectionManagers.withoutConflictDetection(kvs2);
    final SweepStrategyManager ssm2 = SweepStrategyManagers.completelyConservative(kvs2);
    final TestTransactionManagerImpl txManager2 = new TestTransactionManagerImpl(kvs2, timestampService,
            lockClient, lockService, transactionService, cdm2, ssm2);
    SimpleSchemaUpdater updater2 = SimpleSchemaUpdaterImpl.create(kvs2, Namespace.DEFAULT_NAMESPACE);
    updater2.addTable(tableName, definition);
    kvs2.createTable(shortTableName, maxValueSize);
    kvs2.putMetadataForTable(shortTableName, definition.toTableMetadata().persistToBytes());

    GeneralTaskCheckpointer checkpointer = new GeneralTaskCheckpointer("checkpoint", kvs2, txManager2);
    // The namespaced table is migrated under the short name.
    for (final String name : Lists.newArrayList("default." + tableName, shortTableName)) {
        TransactionRangeMigrator rangeMigrator = new TransactionRangeMigratorBuilder().srcTable(name)
                .readTxManager(txManager).txManager(txManager2).checkpointer(checkpointer).build();
        TableMigratorBuilder builder = new TableMigratorBuilder().srcTable(name).partitions(1)
                .executor(PTExecutors.newSingleThreadExecutor()).checkpointer(checkpointer)
                .rangeMigrator(rangeMigrator);
        TableMigrator migrator = builder.build();
        migrator.migrate();
    }
    checkpointer.deleteCheckpoints();

    final KeyValueService verifyKvs = NamespaceMappingKeyValueService
            .create(TableRemappingKeyValueService.create(kvs2, tableMap));
    final ConflictDetectionManager verifyCdm = ConflictDetectionManagers.withoutConflictDetection(verifyKvs);
    final SweepStrategyManager verifySsm = SweepStrategyManagers.completelyConservative(verifyKvs);
    final TestTransactionManagerImpl verifyTxManager = new TestTransactionManagerImpl(verifyKvs,
            timestampService, lockClient, lockService, transactionService, verifyCdm, verifySsm);
    final MutableLong count = new MutableLong();
    for (final String name : Lists.newArrayList(tableName, namespacedTableName)) {
        verifyTxManager.runTaskReadOnly(new TransactionTask<Void, RuntimeException>() {
            @Override
            public Void execute(Transaction t) {
                BatchingVisitable<RowResult<byte[]>> bv = t.getRange(name, RangeRequest.all());
                bv.batchAccept(1000,
                        AbortingVisitors.batching(new AbortingVisitor<RowResult<byte[]>, RuntimeException>() {
                            @Override
                            public boolean visit(RowResult<byte[]> item) {
                                Iterable<Entry<Cell, byte[]>> cells = item.getCells();
                                Entry<Cell, byte[]> e = Iterables.getOnlyElement(cells);
                                Assert.assertEquals(theCell, e.getKey());
                                Assert.assertArrayEquals(theValue, e.getValue());
                                count.increment();
                                return true;
                            }
                        }));
                return null;
            }
        });
    }
    Assert.assertEquals(2L, count.longValue());
}

From source file:com.datatorrent.lib.dedup.Deduper.java

@Override
public void setup(OperatorContext context) {
    this.context = context;
    this.currentWindow = context.getValue(Context.OperatorContext.ACTIVATION_WINDOW_ID);
    sleepTimeMillis = context.getValue(OperatorContext.SPIN_MILLIS);

    bucketManager.setBucketCounters(counters);
    counters.setCounter(CounterKeys.DUPLICATE_EVENTS, new MutableLong());

    bucketManager.startService(this);
    logger.debug("bucket keys at startup {}", waitingEvents.keySet());
    for (long bucketKey : waitingEvents.keySet()) {
        bucketManager.loadBucketData(bucketKey);
    }//from  w w  w .ja va2s .co m
}

From source file:com.datatorrent.lib.io.block.BlockWriter.java

/**
 * Transfers the counters in partitioning.
 *
 * @param target//from   ww w.j av  a2s  .  c  o  m
 *          target counter
 * @param source
 *          removed counter
 */
protected void addCounters(BasicCounters<MutableLong> target, BasicCounters<MutableLong> source) {
    for (Enum<BlockWriter.Counters> key : BlockWriter.Counters.values()) {
        MutableLong tcounter = target.getCounter(key);
        if (tcounter == null) {
            tcounter = new MutableLong();
            target.setCounter(key, tcounter);
        }
        MutableLong scounter = source.getCounter(key);
        if (scounter != null) {
            tcounter.add(scounter.longValue());
        }
    }
}