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

org.mobicents.tools.twiddle.jsleex.RouterCfgCommand Maven / Gradle / Ivy

The newest version!
/*
 * TeleStax, Open Source Cloud Communications
 * Copyright 2011-2017, Telestax Inc and individual contributors
 * by the @authors tag.
 *
 * This program is free software: you can redistribute it and/or modify
 * 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.
 *
 * This program 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 this program.  If not, see 
 */
package org.mobicents.tools.twiddle.jsleex;

import gnu.getopt.Getopt;
import gnu.getopt.LongOpt;

import java.io.PrintWriter;

import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;

import org.jboss.console.twiddle.command.CommandException;
import org.mobicents.tools.twiddle.AbstractSleeCommand;
import org.mobicents.tools.twiddle.Utils;
import org.mobicents.tools.twiddle.op.AccessorOperation;

/**
 * Command to interact with TimerFacilityConfiguration MBean
 * 
 * @author baranowb
 * 
 */
public class RouterCfgCommand extends AbstractSleeCommand {
	private static final String FIELD_ExecutorMapperClassName = "ExecutorMapperClassName";
	private static final String FIELD_EventRouterThreads = "EventRouterThreads";
	private static final String FIELD_CollectStats = "CollectStats";

	public RouterCfgCommand() {
		super("router.cfg", "This command performs operations on Restcomm EventRouterConfiguration MBean.");
		// TODO Auto-generated constructor stub
	}

	@Override
	public void displayHelp() {
		PrintWriter out = context.getWriter();

		out.println(desc);
		out.println();
		out.println("usage: " + name + " <-operation[[arg] | [--option[=arg]]*]>");
		out.println();
		out.println("operation:");
		out	.println("    -m, --mapper                   Performs operation on executor mapper class name. Instance of this class is used to map activity to executor. Exactly one of following options must be present:");
		out.println("            --get                   Returns name of mapper class. Does not require argument.");
		out.println("            --set                   Sets class of mapper, requires argument which FQN of class to be used for mapping.");
		out	.println("    -t, --threads                  Performs operation on threads used by executor. Exactly one of following options must be present:");
		out.println("            --get                   Returns number of threads used by executor. Does not require argument.");
		out.println("            --set                   Sets number of threads used by executor, requires integer argument which is greater than zero.");
		out	.println("    -x, --stats                    Controls if statistics are enabled(true) or disabled(false). Exactly one of following options must be present:");
		out.println("            --get                   Returns boolean indicating if statistics are being enabled or not. Does not require argument.");
		out.println("            --set                   Sets parameter to enable statistics, requires boolean argument.");	
		out.flush();
	}

	@Override
	public ObjectName getBeanOName() throws MalformedObjectNameException, NullPointerException {
		return new ObjectName(Utils.MC_EVENT_ROUTER);
	}

	@Override
	protected void processArguments(String[] args) throws CommandException {
		String sopts = ":mtx";
		LongOpt[] lopts = { 
				
				new LongOpt("mapper", LongOpt.NO_ARGUMENT, null, 'm'),
				new LongOpt("threads", LongOpt.NO_ARGUMENT, null, 't'),
				new LongOpt("stats", LongOpt.NO_ARGUMENT, null, 'x'),
					// options
					new LongOpt("set", LongOpt.REQUIRED_ARGUMENT, null, AccessorOperation.set),
					new LongOpt("get", LongOpt.NO_ARGUMENT, null, AccessorOperation.get)

		};

		Getopt getopt = new Getopt(null, args, sopts, lopts);
		getopt.setOpterr(false);

		int code;
		while ((code = getopt.getopt()) != -1) {
			switch (code) {
			case ':':
				throw new CommandException("Option requires an argument: " + args[getopt.getOptind() - 1]);

			case '?':
				throw new CommandException("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);

			case 'm':

				super.operation = new AccessorOperation(super.context, super.log, this,FIELD_ExecutorMapperClassName,String.class);
				super.operation.buildOperation(getopt, args);

				break;
			case 't':

				super.operation = new AccessorOperation(super.context, super.log, this,FIELD_EventRouterThreads,int.class);
				super.operation.buildOperation(getopt, args);

				break;
			case 'x':

				super.operation = new AccessorOperation(super.context, super.log, this,FIELD_CollectStats,boolean.class);
				super.operation.buildOperation(getopt, args);

				break;

			default:
				throw new CommandException("Command: \"" + getName() + "\", found unexpected opt: " + args[getopt.getOptind() - 1]);

			}
		}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy