/**
 * Copyright (C) 2013 – 2015 SLUB Dresden & Avantgarde Labs GmbH (<code@dswarm.org>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dswarm.converter.pipe.timing;

import java.util.Deque;
import java.util.LinkedList;

import com.codahale.metrics.MetricRegistry;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.culturegraph.mf.framework.StreamPipe;
import org.culturegraph.mf.framework.StreamReceiver;

import org.dswarm.init.Monitoring;

public final class StreamTimer extends TimerBased<StreamReceiver> implements StreamPipe<StreamReceiver> {

	private final Deque<TimingContext> recordContexts;
	private final Deque<TimingContext> entityContexts;

	@Inject
	private StreamTimer(
			@Monitoring final MetricRegistry registry,
			@Assisted final String prefix) {
		super(registry, prefix);

		recordContexts = new LinkedList<>();
		entityContexts = new LinkedList<>();
	}

	@Override
	public void startRecord(final String identifier) {
		final TimingContext context = startMeasurement(identifier);
		recordContexts.offerLast(context);
		getReceiver().startRecord(identifier);
	}

	@Override
	public void endRecord() {
		getReceiver().endRecord();
		final TimingContext context = recordContexts.pollLast();
		if (context != null) {
			context.stop();
		}
	}

	@Override
	public void startEntity(final String name) {
		final TimingContext context = startMeasurement(name);
		entityContexts.offerLast(context);
		getReceiver().startEntity(name);
	}

	@Override
	public void endEntity() {
		getReceiver().endEntity();
		final TimingContext context = entityContexts.pollLast();
		if (context != null) {
			context.stop();
		}
	}

	@Override
	public void literal(final String name, final String value) {
		final TimingContext context = startMeasurement(name);
		getReceiver().literal(name, value);
		context.stop();
	}
}

@@ -1558,26 +1558,25 @@
 urement(
-identifier
+%22records%22
 );%0A%09%09rec
@@ -1932,28 +1932,34 @@
 Measurement(
-name
+%22entities%22
 );%0A%09%09entityC
@@ -2282,115 +2282,121 @@
 %7B%0A%09%09
-final TimingContext context = startMeasurement(name);%0A%09%09getReceiver().literal(name, value);%0A%09%09context.stop(
+getReceiver().literal(name, value);%0A%09%09context.stop();%0A%09%09final TimingContext context = startMeasurement(%22literals%22
 );%0A%09

Use type names instead of identifiers for task execution logging