Package org.apache.commons.lang.mutable

Examples of org.apache.commons.lang.mutable.MutableInt


        xpath.addNamespace("m1", "http://services.samples/xsd2");
        return xpath;
    }

    private void test(ValidateMediator validate, MessageContext synCtx, boolean expectFail) {
        final MutableInt onFailInvoked = new MutableInt();
        TestMediator testMediator = new TestMediator();
        testMediator.setHandler(
                new TestMediateHandler() {
                    public void handle(MessageContext synCtx) {
                        onFailInvoked.setValue(1);
                    }
                });
        // set dummy mediator to be called on fail
        validate.addChild(testMediator);
        validate.mediate(synCtx);
        if (expectFail) {
            assertTrue("Expected ValidateMediator to trigger fail sequence",
                    onFailInvoked.intValue() == 1);
        } else {
            assertTrue("ValidateMediator unexpectedly triggered fail sequence",
                    onFailInvoked.intValue() == 0);
        }
    }
View Full Code Here


    protected Object parseValue(String argStr, MutableInt parsePos) {
        return parseObject(storeDef.getValueSerializer(), argStr, parsePos);
    }

    protected void processPut(String putArgStr) {
        MutableInt parsePos = new MutableInt(0);
        Object key = parseKey(putArgStr, parsePos);
        putArgStr = putArgStr.substring(parsePos.intValue());
        Object value = parseValue(putArgStr, parsePos);
        client.put(key, value);
    }
View Full Code Here

     * @param getAllArgStr space separated list of key strings
     */

    protected void processGetAll(String getAllArgStr) {
        List<Object> keys = new ArrayList<Object>();
        MutableInt parsePos = new MutableInt(0);

        while(true) {
            Object key = parseKey(getAllArgStr, parsePos);
            if(key == null) {
                break;
            }
            keys.add(key);
            getAllArgStr = getAllArgStr.substring(parsePos.intValue());
        }

        Map<Object, Versioned<Object>> vals = client.getAll(keys);
        if(vals.size() > 0) {
            for(Map.Entry<Object, Versioned<Object>> entry: vals.entrySet()) {
View Full Code Here

            commandOutput.println("null");
        }
    }

    protected void processGet(String getArgStr) {
        MutableInt parsePos = new MutableInt(0);
        Object key = parseKey(getArgStr, parsePos);
        printVersioned(client.get(key));
    }
View Full Code Here

        Object key = parseKey(getArgStr, parsePos);
        printVersioned(client.get(key));
    }

    protected void processDelete(String deleteArgStr) {
        MutableInt parsePos = new MutableInt(0);
        Object key = parseKey(deleteArgStr, parsePos);
        client.delete(key);
    }
View Full Code Here

    }

    ParseContext pc = new ParseContext();

    Map<String, byte[]> files = new HashMap<String, byte[]>();
    MutableInt count = new MutableInt();

    pc.set(EmbeddedDocumentExtractor.class, new MyEmbeddedDocumentExtractor(count, files));

    try {
      parser.parse(is, ch, metadata, pc);
    } catch (TikaException ex) {
      logger.warn(String.format(
              "%s: Unpacker failed",
              info.getPath()
      ), ex);

      throw ex;
    }

    if (count.intValue() == 0 && !saveAll) {
      throw new WebApplicationException(Response.Status.NO_CONTENT);
    }

    if (saveAll) {
      files.put(TEXT_FILENAME, text.toByteArray());
View Full Code Here

        List<Throwable> failures = Lists.newArrayList();
        List<NodeValue<ByteArray, byte[]>> nodeValues = Lists.newArrayList();

        Map<ByteArray, MutableInt> keyToSuccessCount = Maps.newHashMap();
        for(ByteArray key: keys)
            keyToSuccessCount.put(key, new MutableInt(0));

        List<Future<GetAllResult>> futures;
        long timeoutMs = timeoutConfig.getOperationTimeout(VoldemortOpCode.GET_ALL_OP_CODE);
        try {
            // TODO What to do about timeouts? They should be longer as getAll
            // is likely to
            // take longer. At the moment, it's just timeoutMs * 3, but should
            // this be based on the number of the keys?
            futures = executor.invokeAll(callables, timeoutMs * 3, TimeUnit.MILLISECONDS);
        } catch(InterruptedException e) {
            throw new InsufficientOperationalNodesException("getAll operation interrupted.", e);
        }
        for(Future<GetAllResult> f: futures) {
            if(f.isCancelled()) {
                logger.warn("Get operation timed out after " + timeoutMs + " ms.");
                continue;
            }
            try {
                GetAllResult getResult = f.get();
                if(getResult.exception != null) {
                    if(getResult.exception instanceof VoldemortApplicationException) {
                        throw (VoldemortException) getResult.exception;
                    }
                    failures.add(getResult.exception);
                    continue;
                }
                for(ByteArray key: getResult.callable.nodeKeys) {
                    List<Versioned<byte[]>> retrieved = getResult.retrieved.get(key);
                    MutableInt successCount = keyToSuccessCount.get(key);
                    successCount.increment();

                    /*
                     * retrieved can be null if there are no values for the key
                     * provided
                     */
                    if(retrieved != null) {
                        List<Versioned<byte[]>> existing = result.get(key);
                        if(existing == null)
                            result.put(key, Lists.newArrayList(retrieved));
                        else
                            existing.addAll(retrieved);
                    }
                }
                nodeValues.addAll(getResult.nodeValues);

            } catch(InterruptedException e) {
                throw new InsufficientOperationalNodesException("getAll operation interrupted.", e);
            } catch(ExecutionException e) {
                // We catch all Throwables apart from Error in the callable, so
                // the else part
                // should never happen
                if(e.getCause() instanceof Error)
                    throw (Error) e.getCause();
                else
                    logger.error(e.getMessage(), e);
            }
        }

        for(ByteArray key: keys) {
            MutableInt successCountWrapper = keyToSuccessCount.get(key);
            int successCount = successCountWrapper.intValue();
            if(successCount < storeDef.getPreferredReads()) {
                List<Node> extraNodes = keyToExtraNodesMap.get(key);
                if(extraNodes != null) {
                    for(Node node: extraNodes) {
                        long startNs = System.nanoTime();
                        try {
                            List<Versioned<byte[]>> values = innerStores.get(node.getId())
                                                                        .get(key,
                                                                             transforms == null ? null
                                                                                               : transforms.get(key));
                            fillRepairReadsValues(nodeValues, key, node, values);
                            List<Versioned<byte[]>> versioneds = result.get(key);
                            if(versioneds == null)
                                result.put(key, Lists.newArrayList(values));
                            else
                                versioneds.addAll(values);
                            recordSuccess(node, startNs);
                            if(++successCount >= storeDef.getPreferredReads())
                                break;

                        } catch(UnreachableStoreException e) {
                            failures.add(e);
                            recordException(node, startNs, e);
                        } catch(VoldemortApplicationException e) {
                            throw e;
                        } catch(Exception e) {
                            logger.warn("Error in GET_ALL on node " + node.getId() + "("
                                                + node.getHost() + ")",
                                        e);
                            failures.add(e);
                        }
                    }
                }
            }
            successCountWrapper.setValue(successCount);
        }

        repairReads(nodeValues, repairReads && (transforms == null || transforms.size() == 0));

        for(Map.Entry<ByteArray, MutableInt> mapEntry: keyToSuccessCount.entrySet()) {
View Full Code Here

                    return;
            } else {
                Map<ByteArray, List<Versioned<byte[]>>> values = (Map<ByteArray, List<Versioned<byte[]>>>) response.getValue();

                for (ByteArray key: response.getKey()) {
                    MutableInt successCount = pipelineData.getSuccessCount(key);
                    successCount.increment();

                    List<Versioned<byte[]>> retrieved = values.get(key);
                    /*
                     * retrieved can be null if there are no values for the key
                     * provided
 
View Full Code Here

    public void execute(Pipeline pipeline) {
        Map<ByteArray, List<Versioned<byte[]>>> result = pipelineData.getResult();

        for(ByteArray key: keys) {
            boolean zoneRequirement = false;
            MutableInt successCount = pipelineData.getSuccessCount(key);

            if(logger.isDebugEnabled())
                logger.debug("GETALL for key " + ByteUtils.toHexString(key.get()) + " (keyRef: "
                             + System.identityHashCode(key) + ") successes: "
                             + successCount.intValue() + " preferred: " + preferred + " required: "
                             + required);

            if(successCount.intValue() >= preferred) {
                if(pipelineData.getZonesRequired() != null && pipelineData.getZonesRequired() > 0) {

                    if(pipelineData.getKeyToZoneResponse().containsKey(key)) {
                        int zonesSatisfied = pipelineData.getKeyToZoneResponse().get(key).size();
                        if(zonesSatisfied >= (pipelineData.getZonesRequired() + 1)) {
                            continue;
                        } else {
                            zoneRequirement = true;
                        }
                    } else {
                        zoneRequirement = true;
                    }

                } else {
                    continue;
                }
            }

            List<Node> extraNodes = pipelineData.getKeyToExtraNodesMap().get(key);
            Map<ByteArray, byte[]> transforms = pipelineData.getTransforms();

            if(extraNodes == null)
                continue;

            for(Node node: extraNodes) {
                long start = System.nanoTime();

                try {
                    Store<ByteArray, byte[], byte[]> store = stores.get(node.getId());
                    List<Versioned<byte[]>> values;
                    if(transforms == null)
                        values = store.get(key, null);
                    else
                        values = store.get(key, transforms.get(key));

                    if(values.size() != 0) {
                        if(result.get(key) == null)
                            result.put(key, Lists.newArrayList(values));
                        else
                            result.get(key).addAll(values);
                    }

                    Map<ByteArray, List<Versioned<byte[]>>> map = new HashMap<ByteArray, List<Versioned<byte[]>>>();
                    map.put(key, values);

                    Response<Iterable<ByteArray>, Map<ByteArray, List<Versioned<byte[]>>>> response = new Response<Iterable<ByteArray>, Map<ByteArray, List<Versioned<byte[]>>>>(node,
                                                                                                                                                                                 Arrays.asList(key),
                                                                                                                                                                                 map,
                                                                                                                                                                                 ((System.nanoTime() - start) / Time.NS_PER_MS));

                    successCount.increment();
                    pipelineData.getResponses().add(response);
                    failureDetector.recordSuccess(response.getNode(), response.getRequestTime());

                    if(logger.isDebugEnabled())
                        logger.debug("GET for key " + ByteUtils.toHexString(key.get())
                                     + " (keyRef: " + System.identityHashCode(key)
                                     + ") successes: " + successCount.intValue() + " preferred: "
                                     + preferred + " required: " + required
                                     + " new GET success on node " + node.getId());

                    HashSet<Integer> zoneResponses = null;
                    if(pipelineData.getKeyToZoneResponse().containsKey(key)) {
                        zoneResponses = pipelineData.getKeyToZoneResponse().get(key);
                    } else {
                        zoneResponses = new HashSet<Integer>();
                        pipelineData.getKeyToZoneResponse().put(key, zoneResponses);
                    }
                    zoneResponses.add(response.getNode().getZoneId());

                    if(zoneRequirement) {
                        if(zoneResponses.size() >= pipelineData.getZonesRequired())
                            break;
                    } else {
                        if(successCount.intValue() >= preferred)
                            break;
                    }

                } catch(Exception e) {
                    long requestTime = (System.nanoTime() - start) / Time.NS_PER_MS;

                    if(handleResponseError(e, node, requestTime, pipeline, failureDetector))
                        return;
                }
            }
        }

        for(ByteArray key: keys) {
            MutableInt successCount = pipelineData.getSuccessCount(key);

            if(successCount.intValue() < required) {
                // if we allow partial results, then just remove keys that did
                // not meet 'required' guarantee; else raise error
                if(allowPartial) {
                    if(logger.isDebugEnabled()) {
                        logger.debug("Excluding Key " + ByteUtils.toHexString(key.get())
                                     + " from partial get_all result");
                    }
                    result.remove(key);
                } else {
                    pipelineData.setFatalError(new InsufficientOperationalNodesException(required
                                                                                                 + " "
                                                                                                 + pipeline.getOperation()
                                                                                                           .getSimpleName()
                                                                                                 + "s required, but "
                                                                                                 + successCount.intValue()
                                                                                                 + " succeeded. Failing nodes : "
                                                                                                 + pipelineData.getFailedNodes(),
                                                                                         pipelineData.getFailures()));
                    pipeline.addEvent(Event.ERROR);
                    return;
View Full Code Here

    public void setKeyToExtraNodesMap(Map<ByteArray, List<Node>> keyToExtraNodesMap) {
        this.keyToExtraNodesMap = keyToExtraNodesMap;
    }

    public MutableInt getSuccessCount(ByteArray key) {
        MutableInt value = keyToSuccessCount.get(key);

        if(value == null) {
            value = new MutableInt(0);
            keyToSuccessCount.put(key, value);
        }

        return value;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.lang.mutable.MutableInt

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.