
com.anrisoftware.sscontrol.scripts.unix.RestartServicesLogger Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014-2015 Erwin Müller
*
* This file is part of sscontrol-scripts-unix.
*
* sscontrol-scripts-unix is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* sscontrol-scripts-unix is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with sscontrol-scripts-unix. If not, see .
*/
package com.anrisoftware.sscontrol.scripts.unix;
import static com.anrisoftware.sscontrol.scripts.unix.RestartServicesLogger._.command_null;
import static com.anrisoftware.sscontrol.scripts.unix.RestartServicesLogger._.restarted_service_debug;
import static com.anrisoftware.sscontrol.scripts.unix.RestartServicesLogger._.restarted_service_info;
import static com.anrisoftware.sscontrol.scripts.unix.RestartServicesLogger._.restarted_service_trace;
import static com.anrisoftware.sscontrol.scripts.unix.RestartServicesLogger._.services_null;
import static org.apache.commons.lang3.Validate.notNull;
import java.util.Map;
import javax.inject.Inject;
import com.anrisoftware.globalpom.exec.api.ProcessTask;
import com.anrisoftware.globalpom.exec.runcommands.RunCommands;
import com.anrisoftware.globalpom.exec.runcommands.RunCommandsArg;
import com.anrisoftware.globalpom.log.AbstractLogger;
/**
* Logging for {@link RestartServices}.
*
* @author Erwin Mueller, [email protected]
* @since 1.0
*/
class RestartServicesLogger extends AbstractLogger {
private static final String SERVICES_ARG = "services";
private static final String COMMAND_ARG = "command";
enum _ {
command_null("Restart command argument '%s' must be set"),
services_null("Services list argument '%s' must be set"),
restarted_service_trace("Restarted service {} for {}, {}."),
restarted_service_debug("Restarted service {} for {}."),
restarted_service_info("Restarted service for script {}.");
private String name;
private _(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
@Inject
private RunCommandsArg runCommandsArg;
/**
* Sets the context of the logger to {@link RestartServices}.
*/
public RestartServicesLogger() {
super(RestartServices.class);
}
void restartedDone(Object parent, RunCommands runCommands,
ProcessTask task, Map args) {
if (isTraceEnabled()) {
trace(restarted_service_trace, args, parent, task);
} else if (isDebugEnabled()) {
debug(restarted_service_debug, args, parent);
} else {
info(restarted_service_info, parent);
}
if (runCommands != null) {
runCommands.add(args.get(COMMAND_ARG), args);
}
}
void checkArgs(Map args) {
notNull(args.get(COMMAND_ARG), command_null.toString(), COMMAND_ARG);
notNull(args.get(SERVICES_ARG), services_null.toString(), SERVICES_ARG);
}
RunCommands runCommands(Map args, Object parent) {
return runCommandsArg.runCommands(args, parent);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy