Package com.yammer.metrics.core

Examples of com.yammer.metrics.core.TimerContext


        for (int j = 0; j < session.getSuperColumns(); j++)
        {
            String superColumn = 'S' + Integer.toString(j);
            ColumnParent parent = new ColumnParent("Super1").setSuper_column(superColumn.getBytes(UTF_8));

            TimerContext context = session.latency.time();

            boolean success = false;
            String exceptionMessage = null;

            for (int t = 0; t < session.getRetryTimes(); t++)
            {
                if (success)
                    break;

                try
                {
                    List<ColumnOrSuperColumn> columns;
                    columns = client.get_slice(key, parent, predicate, session.getConsistencyLevel());
                    success = (columns.size() != 0);
                }
                catch (Exception e)
                {
                    exceptionMessage = getExceptionMessage(e);
                    success = false;
                }
            }

            if (!success)
            {
                error(String.format("Operation [%d] retried %d times - error reading key %s %s%n",
                                    index,
                                    session.getRetryTimes(),
                                    new String(rawKey),
                                    (exceptionMessage == null) ? "" : "(" + exceptionMessage + ")"));
            }

            session.operations.getAndIncrement();
            session.keys.getAndIncrement();
            context.stop();
        }
    }
View Full Code Here


        ColumnParent parent = new ColumnParent("Standard1");

        byte[] key = generateKey();
        ByteBuffer keyBuffer = ByteBuffer.wrap(key);

        TimerContext context = session.latency.time();

        boolean success = false;
        String exceptionMessage = null;

        for (int t = 0; t < session.getRetryTimes(); t++)
        {
            if (success)
                break;

            try
            {
                List<ColumnOrSuperColumn> columns;
                columns = client.get_slice(keyBuffer, parent, predicate, session.getConsistencyLevel());
                success = (columns.size() != 0);
            }
            catch (Exception e)
            {
                exceptionMessage = getExceptionMessage(e);
                success = false;
            }
        }

        if (!success)
        {
            error(String.format("Operation [%d] retried %d times - error reading key %s %s%n",
                                index,
                                session.getRetryTimes(),
                                new String(key),
                                (exceptionMessage == null) ? "" : "(" + exceptionMessage + ")"));
        }

        session.operations.getAndIncrement();
        session.keys.getAndIncrement();
        context.stop();
    }
View Full Code Here

                            buffer.put(v, v);
                            v++;
                        }
                        mods -= c;
                    }
                    TimerContext ctxt;
                    ctxt = TREE_TIMER.time();
                    canon.putAll(buffer);
                    ctxt.stop();
                    ctxt = BTREE_TIMER.time();
                    Object[] next = null;
                    while (next == null)
                        next = BTree.update(btree, ICMP, buffer.keySet(), true, SPORADIC_ABORT);
                    btree = next;
                    ctxt.stop();

                    if (!BTree.isWellFormed(btree, ICMP))
                    {
                        System.out.println("ERROR: Not well formed");
                        throw new AssertionError("Not well formed!");
View Full Code Here

        }
      }

      void runCore() throws Exception {

        final TimerContext timer = pollTime.time();

        SocketUDT.epollWait0( //
            epollID, readBuffer, writeBuffer, sizeBuffer, 0);

        timer.stop();

      }

    };
View Full Code Here

        }
      }

      void runCore() throws Exception {

        final TimerContext timer = pollTimeOne.time();

        SocketUDT.epollWait0( //
            epollID, readBuffer, writeBuffer, sizeBuffer, 0);

        timer.stop();

      }

    };

    final Runnable epollTaskTwo = new Runnable() {

      final IntBuffer readBuffer = HelpUDT.newDirectIntBufer(1024);
      final IntBuffer writeBuffer = HelpUDT.newDirectIntBufer(1024);
      final IntBuffer sizeBuffer = HelpUDT.newDirectIntBufer(1024);

      @Override
      public void run() {
        try {

          while (isOn.get()) {
            runCore();
          }

        } catch (final Exception e) {
          log.error("", e);
        }
      }

      void runCore() throws Exception {

        final TimerContext timer = pollTimeTwo.time();

        SocketUDT.epollWait0( //
            epollID, readBuffer, writeBuffer, sizeBuffer, 0);

        timer.stop();

      }

    };
View Full Code Here

      void runCore() throws Exception {

        buffer.rewind();
        buffer.putLong(0, sequence++);

        final TimerContext timer = sendTime.time();

        final int count = client.send(buffer);

        timer.stop();

        if (count != size) {
          throw new Exception("count");
        }

        sendRate.mark(count);

      }

    };

    final Runnable serverTask = new Runnable() {

      @Override
      public void run() {
        try {
          while (isOn.get()) {
            runCore();
          }
        } catch (final Exception e) {
          log.error("", e);
        }
      }

      final ByteBuffer buffer = ByteBuffer.allocateDirect(size);

      long sequence;

      void runCore() throws Exception {

        buffer.rewind();

        final TimerContext timer = recvTime.time();

        final int count = server.receive(buffer);

        timer.stop();

        if (count != size) {
          throw new Exception("count");
        }
View Full Code Here

                System.err.println("Error during query: " + e.getMessage());
            }
        }

        protected void handle(QueryGenerator.Request request) {
            TimerContext context = reporter.latencies.time();
            try {
                request.execute(session);
            } finally {
                context.stop();
                reporter.requests.mark();
            }
        }
View Full Code Here

        awaitUninterruptibly(shutdownLatch);
    }

    protected void handle(QueryGenerator.Request request) {

        final TimerContext timerContext = reporter.latencies.time();
        ResultSetFuture resultSetFuture = request.executeAsync(session);
        Futures.addCallback(resultSetFuture, new FutureCallback<ResultSet>() {
            @Override
            public void onSuccess(final ResultSet result) {
                timerContext.stop();
                reporter.requests.mark();
                request();
            }

            @Override
            public void onFailure(final Throwable t) {
                // Could do better I suppose
                System.err.println("Error during request: " + t);
                timerContext.stop();
                reporter.requests.mark();
                request();
            }
        }, executorService);
    }
View Full Code Here

    public boolean isThreadSafe() {
        return isThreadSafe;
    }

    protected void handleInputEvent(Event event) {
        TimerContext timerContext = null;
        if (processingTimer != null) {
            // if timing enabled
            timerContext = processingTimer.time();
        }
        Object object;
        if (isThreadSafe) {
            object = new Object(); // a dummy object TODO improve this.
        } else {
            object = this;
        }
        synchronized (object) {
            if (!recoveryAttempted) {
                recover();
                recoveryAttempted = true;
            }

            /* Dispatch onEvent() method. */
            overloadDispatcher.dispatchEvent(this, event);

            /* Dispatch onTrigger() method. */
            if (haveTriggers && isTrigger(event)) {
                overloadDispatcher.dispatchTrigger(this, event);
            }

            eventCount++;

            dirty = true;

            if (isCheckpointable()) {
                checkpoint();
            }
        }
        if (timerContext != null) {
            // if timing enabled
            timerContext.stop();
        }
    }
View Full Code Here

        }

        String key = String.format("%0" + session.getTotalKeysLength() + "d", index);
        String formattedQuery = null;

        TimerContext context = session.latency.time();

        boolean success = false;
        String exceptionMessage = null;

        for (int t = 0; t < session.getRetryTimes(); t++)
        {
            if (success)
                break;

            try
            {
                if (session.usePreparedStatements())
                {
                    Integer stmntId = getPreparedStatement(client, cqlQuery);
                    if (session.cqlVersion.startsWith("3"))
                        client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes())), session.getConsistencyLevel());
                    else
                        client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes())));
                }
                else
                {
                    if (formattedQuery == null)
                        formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))));
                    if (session.cqlVersion.startsWith("3"))
                        client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel());
                    else
                        client.execute_cql_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE);
                }

                success = true;
            }
            catch (Exception e)
            {
                exceptionMessage = getExceptionMessage(e);
                success = false;
            }
        }

        if (!success)
        {
            error(String.format("Operation [%d] retried %d times - error incrementing key %s %s%n",
                                index,
                                session.getRetryTimes(),
                                key,
                                (exceptionMessage == null) ? "" : "(" + exceptionMessage + ")"));
        }

        session.operations.getAndIncrement();
        session.keys.getAndIncrement();
        context.stop();
    }
View Full Code Here

TOP

Related Classes of com.yammer.metrics.core.TimerContext

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.