All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.iopipe.plugin.eventinfo.ValueAcceptor Maven / Gradle / Ivy

Go to download

This project provides analytics and distributed tracing for event-driven applications running on AWS Lambda using the IOpipe service.

The newest version!
package com.iopipe.plugin.eventinfo;

import com.iopipe.CustomMetric;
import java.util.ArrayList;
import java.util.List;

/**
 * This class is used to accept values which should be stored in custom
 * metrics in the generated report.
 *
 * @since 2018/05/02
 */
public final class ValueAcceptor
{
	/** The event type used. */
	protected final String eventtype;
	
	/** The key prefix. */
	protected final String prefix;
	
	/** The target list for recorded metrics. */
	private final List _metrics =
		new ArrayList<>();
	
	/**
	 * Initializes the value acceptor.
	 *
	 * @param __et The event type used.
	 * @throws NullPointerException On null arguments.
	 * @since 2018/05/02
	 */
	public ValueAcceptor(String __et)
		throws NullPointerException
	{
		if (__et == null)
			throw new NullPointerException();
		
		this.eventtype = __et;
		
		// Generate prefix
		this.prefix = "@iopipe/event-info." + __et + ".";
		
		// Record initial metric
		this._metrics.add(
			new CustomMetric("@iopipe/event-info.eventType", __et));
	}
	
	/**
	 * Accepts the given key and value.
	 *
	 * @param __key The key.
	 * @param __val The value, if this is {@code null} then nothing will be
	 * reported.
	 * @throws NullPointerException If no key was specified.
	 * @since 2018/05/02
	 */
	public final void accept(String __key, String __val)
		throws NullPointerException
	{
		if (__key == null)
			throw new NullPointerException();
		
		if (__val != null)
			this._metrics.add(new CustomMetric(this.prefix + __key, __val));
	}
	
	/**
	 * Accepts the given key and value.
	 *
	 * @param __key The key.
	 * @param __val The value.
	 * @throws NullPointerException If no key was specified.
	 * @since 2018/05/02
	 */
	public final void accept(String __key, long __val)
		throws NullPointerException
	{
		if (__key == null)
			throw new NullPointerException();
		
		this._metrics.add(new CustomMetric(this.prefix + __key, __val));
	}
	
	/**
	 * Returns all of the generated custom metrics.
	 *
	 * @return The array of created custom metrics.
	 * @since 2018/05/02
	 */
	public final CustomMetric[] get()
	{
		List metrics = this._metrics;
		return metrics.toArray(new CustomMetric[metrics.size()]);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy