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

me.bazhenov.docker.NotificationMethod Maven / Gradle / Ivy

There is a newer version: 1.6.2
Show newest version
package me.bazhenov.docker;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import static java.util.Objects.requireNonNull;

final class NotificationMethod {

	private ContainerNamespace namespace;
	private final Method method;
	private List arguments;

	NotificationMethod(ContainerNamespace namespace, Method method, List arguments) {
		this.namespace = requireNonNull(namespace);
		this.method = requireNonNull(method);
		this.arguments = requireNonNull(arguments);
	}

	void call(Object test) {
		Object[] args = new Integer[arguments.size()];
		for (int i = 0; i < args.length; i++) {
			PortRef port = arguments.get(i);
			args[i] = namespace.lookupHostPort(port.getContainerDefinition(), port.getContainerPort());
		}
		try {
			method.invoke(test, args);
		} catch (InvocationTargetException | IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}

	Method getMethod() {
		return method;
	}

	List getArguments() {
		return arguments;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy