private void leaveGroup(long time) { if (Timing.isEnabled() && currentGroup != null) { Timing.stop(requestTimer, time); requestTimer = null; currentGroup = null; Timing.exitScope(); } }
private void enterGroup(String group, long time) { if (Timing.isEnabled()) { Timing.enterScope(); requestTimer = Timing.startRequest(GWT_PREFIX + group); requestTimer.start(time); currentGroup = group; } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; Timer timer = Timing.startRequest(req.getRequestURI()); try { chain.doFilter(req, response); } finally { Timing.stop(timer); } }
private void loadStageOne(final StageZero zero) { final Timer timer = Timing.start("Stage One"); createStageOneLoader(zero) .call( new Accessor<StageOne>() { @Override public void use(StageOne x) { Timing.stop(timer); loadStageTwo(x); } }); }
private void loadStageZero() { final Timer timer = Timing.start("Stage Zero"); createStageZeroLoader() .call( new Accessor<StageZero>() { @Override public void use(StageZero x) { Timing.stop(timer); loadStageOne(x); } }); }
@Override public void onStatisticsEvent(StatisticsEvent event) { String group = event.getEventGroupKey(); String type = (String) event.getExtraParameter(PARAM_TYPE); if (TYPE_BEGIN.equals(type)) { enterGroup(group, (long) event.getMillis()); } else { if (TYPE_END.equals(type)) { leaveGroup((long) event.getMillis()); } else { if (!group.equals(currentGroup)) { leaveGroup((long) event.getMillis()); enterGroup(group, (long) event.getMillis()); } Timing.record(GWT_PREFIX + type, (int) ((long) event.getMillis() - previousCallTimestamp)); } } previousCallTimestamp = (long) event.getMillis(); }
private void loadStageTwo(final StageOne one) { final Timer timer = Timing.start("Stage Two"); SchedulerInstance.getHighPriorityTimer() .schedule( new Scheduler.Task() { @Override public void execute() { createStageTwoLoader(one) .call( new Accessor<StageTwo>() { @Override public void use(StageTwo x) { Timing.stop(timer); loadStageThree(x); } }); } }); }
private void loadStageThree(final StageTwo two) { final Timer timer = Timing.start("Stage Tree"); SchedulerInstance.getHighPriorityTimer() .schedule( new Scheduler.Task() { @Override public void execute() { createStageThreeLoader(two) .call( new Accessor<StageThree>() { @Override public void use(StageThree x) { Timing.stop(timer); finish(); } }); } }); }
@Override public void message(final int sequenceNo, Message message) { final String messageName = "/" + message.getClass().getSimpleName(); final Timer profilingTimer = Timing.startRequest(messageName); if (message instanceof Rpc.CancelRpc) { final ServerRpcController controller = activeRpcs.get(sequenceNo); if (controller == null) { throw new IllegalStateException("Trying to cancel an RPC that is not active!"); } else { LOG.info("Cancelling open RPC " + sequenceNo); controller.cancel(); } } else if (message instanceof ProtocolAuthenticate) { // Workaround for bug: http://codereview.waveprotocol.org/224001/ // When we get this message, either the connection will not be logged in // (loggedInUser == null) or the connection will have been authenticated // via cookies // (in which case loggedInUser must match the authenticated user, and // this message has no // effect). ProtocolAuthenticate authMessage = (ProtocolAuthenticate) message; ParticipantId authenticatedAs = authenticate(authMessage.getToken()); Preconditions.checkArgument(authenticatedAs != null, "Auth token invalid"); Preconditions.checkState( loggedInUser == null || loggedInUser.equals(authenticatedAs), "Session already authenticated as a different user"); loggedInUser = authenticatedAs; LOG.info("Session authenticated as " + loggedInUser); sendMessage(sequenceNo, ProtocolAuthenticationResult.getDefaultInstance()); } else if (provider.registeredServices.containsKey(message.getDescriptorForType())) { if (activeRpcs.containsKey(sequenceNo)) { throw new IllegalStateException( "Can't invoke a new RPC with a sequence number already in use."); } else { final RegisteredServiceMethod serviceMethod = provider.registeredServices.get(message.getDescriptorForType()); // Create the internal ServerRpcController used to invoke the call. final ServerRpcController controller = new ServerRpcControllerImpl( message, serviceMethod.service, serviceMethod.method, loggedInUser, new RpcCallback<Message>() { @Override public synchronized void run(Message message) { if (message instanceof Rpc.RpcFinished || !serviceMethod.method.getOptions().getExtension(Rpc.isStreamingRpc)) { // This RPC is over - remove it from the map. boolean failed = message instanceof Rpc.RpcFinished ? ((Rpc.RpcFinished) message).getFailed() : false; LOG.fine("RPC " + sequenceNo + " is now finished, failed = " + failed); if (failed) { LOG.info("error = " + ((Rpc.RpcFinished) message).getErrorText()); } activeRpcs.remove(sequenceNo); } sendMessage(sequenceNo, message); if (profilingTimer != null) { Timing.stop(profilingTimer); } } }); // Kick off a new thread specific to this RPC. activeRpcs.put(sequenceNo, controller); provider.threadPool.execute(controller); } } else { // Sent a message type we understand, but don't expect - erronous case! throw new IllegalStateException( "Got expected but unknown message (" + message + ") for sequence: " + sequenceNo); } }