Search in sources :

Example 16 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project tika by apache.

the class UnpackerResource method process.

private Map<String, byte[]> process(InputStream is, @Context HttpHeaders httpHeaders, @Context UriInfo info, boolean saveAll) throws Exception {
    Metadata metadata = new Metadata();
    ParseContext pc = new ParseContext();
    Parser parser = TikaResource.createParser();
    if (parser instanceof DigestingParser) {
        //no need to digest for unwrapping
        parser = ((DigestingParser) parser).getWrappedParser();
    }
    TikaResource.fillMetadata(parser, metadata, pc, httpHeaders.getRequestHeaders());
    TikaResource.logRequest(LOG, info, metadata);
    ContentHandler ch;
    ByteArrayOutputStream text = new ByteArrayOutputStream();
    if (saveAll) {
        ch = new BodyContentHandler(new RichTextContentHandler(new OutputStreamWriter(text, UTF_8)));
    } else {
        ch = new DefaultHandler();
    }
    Map<String, byte[]> files = new HashMap<>();
    MutableInt count = new MutableInt();
    pc.set(EmbeddedDocumentExtractor.class, new MyEmbeddedDocumentExtractor(count, files));
    TikaResource.parse(parser, LOG, info.getPath(), is, ch, metadata, pc);
    if (count.intValue() == 0 && !saveAll) {
        throw new WebApplicationException(Response.Status.NO_CONTENT);
    }
    if (saveAll) {
        files.put(TEXT_FILENAME, text.toByteArray());
        ByteArrayOutputStream metaStream = new ByteArrayOutputStream();
        metadataToCsv(metadata, metaStream);
        files.put(META_FILENAME, metaStream.toByteArray());
    }
    return files;
}
Also used : BodyContentHandler(org.apache.tika.sax.BodyContentHandler) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) Metadata(org.apache.tika.metadata.Metadata) DigestingParser(org.apache.tika.parser.DigestingParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BodyContentHandler(org.apache.tika.sax.BodyContentHandler) ContentHandler(org.xml.sax.ContentHandler) RichTextContentHandler(org.apache.tika.sax.RichTextContentHandler) Parser(org.apache.tika.parser.Parser) OfficeParser(org.apache.tika.parser.microsoft.OfficeParser) DigestingParser(org.apache.tika.parser.DigestingParser) DefaultHandler(org.xml.sax.helpers.DefaultHandler) RichTextContentHandler(org.apache.tika.sax.RichTextContentHandler) MutableInt(org.apache.commons.lang.mutable.MutableInt) ParseContext(org.apache.tika.parser.ParseContext) OutputStreamWriter(java.io.OutputStreamWriter)

Example 17 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project gatk-protected by broadinstitute.

the class AnnotateVcfWithBamDepth method apply.

@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
    final MutableInt depth = new MutableInt(0);
    for (final GATKRead read : readsContext) {
        if (!read.failsVendorQualityCheck() && !read.isDuplicate() && !read.isUnmapped() && read.getEnd() > read.getStart() && new SimpleInterval(read).contains(vc)) {
            depth.increment();
        }
    }
    vcfWriter.add(new VariantContextBuilder(vc).attribute(POOLED_BAM_DEPTH_ANNOTATION_NAME, depth.intValue()).make());
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) MutableInt(org.apache.commons.lang.mutable.MutableInt) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval)

Example 18 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project hbase by apache.

the class ZKAsyncRegistry method getMetaRegionLocation.

@Override
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
    CompletableFuture<RegionLocations> future = new CompletableFuture<>();
    HRegionLocation[] locs = new HRegionLocation[znodePaths.metaReplicaZNodes.size()];
    MutableInt remaining = new MutableInt(locs.length);
    znodePaths.metaReplicaZNodes.forEach((replicaId, path) -> {
        if (replicaId == DEFAULT_REPLICA_ID) {
            exec(zk.getData(), path, ZKAsyncRegistry::getMetaProto).whenComplete((proto, error) -> {
                if (error != null) {
                    future.completeExceptionally(error);
                    return;
                }
                if (proto == null) {
                    future.completeExceptionally(new IOException("Meta znode is null"));
                    return;
                }
                Pair<RegionState.State, ServerName> stateAndServerName = getStateAndServerName(proto);
                if (stateAndServerName.getFirst() != RegionState.State.OPEN) {
                    future.completeExceptionally(new IOException("Meta region is in state " + stateAndServerName.getFirst()));
                    return;
                }
                locs[DEFAULT_REPLICA_ID] = new HRegionLocation(getRegionInfoForDefaultReplica(FIRST_META_REGIONINFO), stateAndServerName.getSecond());
                tryComplete(remaining, locs, future);
            });
        } else {
            exec(zk.getData(), path, ZKAsyncRegistry::getMetaProto).whenComplete((proto, error) -> {
                if (future.isDone()) {
                    return;
                }
                if (error != null) {
                    LOG.warn("Failed to fetch " + path, error);
                    locs[replicaId] = null;
                } else if (proto == null) {
                    LOG.warn("Meta znode for replica " + replicaId + " is null");
                    locs[replicaId] = null;
                } else {
                    Pair<RegionState.State, ServerName> stateAndServerName = getStateAndServerName(proto);
                    if (stateAndServerName.getFirst() != RegionState.State.OPEN) {
                        LOG.warn("Meta region for replica " + replicaId + " is in state " + stateAndServerName.getFirst());
                        locs[replicaId] = null;
                    } else {
                        locs[replicaId] = new HRegionLocation(getRegionInfoForReplica(FIRST_META_REGIONINFO, replicaId), stateAndServerName.getSecond());
                    }
                }
                tryComplete(remaining, locs, future);
            });
        }
    });
    return future;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) CompletableFuture(java.util.concurrent.CompletableFuture) RegionState(org.apache.hadoop.hbase.master.RegionState) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) RegionState(org.apache.hadoop.hbase.master.RegionState) MutableInt(org.apache.commons.lang.mutable.MutableInt) ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException) Pair(org.apache.hadoop.hbase.util.Pair)

Example 19 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project hbase by apache.

the class LoadIncrementalHFiles method checkHFilesCountPerRegionPerFamily.

private boolean checkHFilesCountPerRegionPerFamily(final Multimap<ByteBuffer, LoadQueueItem> regionGroups) {
    for (Entry<ByteBuffer, ? extends Collection<LoadQueueItem>> e : regionGroups.asMap().entrySet()) {
        final Collection<LoadQueueItem> lqis = e.getValue();
        HashMap<byte[], MutableInt> filesMap = new HashMap<>();
        for (LoadQueueItem lqi : lqis) {
            MutableInt count = filesMap.get(lqi.family);
            if (count == null) {
                count = new MutableInt();
                filesMap.put(lqi.family, count);
            }
            count.increment();
            if (count.intValue() > maxFilesPerRegionPerFamily) {
                LOG.error("Trying to load more than " + maxFilesPerRegionPerFamily + " hfiles to family " + Bytes.toStringBinary(lqi.family) + " of region with start key " + Bytes.toStringBinary(e.getKey()));
                return false;
            }
        }
    }
    return true;
}
Also used : HashMap(java.util.HashMap) MutableInt(org.apache.commons.lang.mutable.MutableInt) ByteBuffer(java.nio.ByteBuffer)

Example 20 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project hbase by apache.

the class ZkSplitLogWorkerCoordination method grabTask.

/**
   * try to grab a 'lock' on the task zk node to own and execute the task.
   * <p>
   * @param path zk node for the task
   */
private void grabTask(String path) {
    Stat stat = new Stat();
    byte[] data;
    synchronized (grabTaskLock) {
        currentTask = path;
        workerInGrabTask = true;
        if (Thread.interrupted()) {
            return;
        }
    }
    try {
        try {
            if ((data = ZKUtil.getDataNoWatch(watcher, path, stat)) == null) {
                SplitLogCounters.tot_wkr_failed_to_grab_task_no_data.incrementAndGet();
                return;
            }
        } catch (KeeperException e) {
            LOG.warn("Failed to get data for znode " + path, e);
            SplitLogCounters.tot_wkr_failed_to_grab_task_exception.incrementAndGet();
            return;
        }
        SplitLogTask slt;
        try {
            slt = SplitLogTask.parseFrom(data);
        } catch (DeserializationException e) {
            LOG.warn("Failed parse data for znode " + path, e);
            SplitLogCounters.tot_wkr_failed_to_grab_task_exception.incrementAndGet();
            return;
        }
        if (!slt.isUnassigned()) {
            SplitLogCounters.tot_wkr_failed_to_grab_task_owned.incrementAndGet();
            return;
        }
        currentVersion = attemptToOwnTask(true, watcher, server.getServerName(), path, slt.getMode(), stat.getVersion());
        if (currentVersion < 0) {
            SplitLogCounters.tot_wkr_failed_to_grab_task_lost_race.incrementAndGet();
            return;
        }
        if (ZKSplitLog.isRescanNode(watcher, currentTask)) {
            ZkSplitLogWorkerCoordination.ZkSplitTaskDetails splitTaskDetails = new ZkSplitLogWorkerCoordination.ZkSplitTaskDetails();
            splitTaskDetails.setTaskNode(currentTask);
            splitTaskDetails.setCurTaskZKVersion(new MutableInt(currentVersion));
            endTask(new SplitLogTask.Done(server.getServerName(), slt.getMode()), SplitLogCounters.tot_wkr_task_acquired_rescan, splitTaskDetails);
            return;
        }
        LOG.info("worker " + server.getServerName() + " acquired task " + path);
        SplitLogCounters.tot_wkr_task_acquired.incrementAndGet();
        getDataSetWatchAsync();
        submitTask(path, slt.getMode(), currentVersion, reportPeriod);
        // after a successful submit, sleep a little bit to allow other RSs to grab the rest tasks
        try {
            int sleepTime = RandomUtils.nextInt(500) + 500;
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while yielding for other region servers", e);
            Thread.currentThread().interrupt();
        }
    } finally {
        synchronized (grabTaskLock) {
            workerInGrabTask = false;
            // clear the interrupt from stopTask() otherwise the next task will
            // suffer
            Thread.interrupted();
        }
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) MutableInt(org.apache.commons.lang.mutable.MutableInt) SplitLogTask(org.apache.hadoop.hbase.SplitLogTask) KeeperException(org.apache.zookeeper.KeeperException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

MutableInt (org.apache.commons.lang.mutable.MutableInt)35 List (java.util.List)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 ArrayList (java.util.ArrayList)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Map (java.util.Map)4 Test (org.junit.Test)4 Versioned (voldemort.versioning.Versioned)4 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 MutableObject (org.apache.commons.lang.mutable.MutableObject)3 DateTime (org.joda.time.DateTime)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Random (java.util.Random)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 CompositeName (javax.naming.CompositeName)2