Start command polling

@param command
The command to poll
@throws DevFailed
165973
public synchronized void startCommandPolling(final CommandImpl command) throws DevFailed {
        addCommandPolling(command);
        LOGGER.debug("starting command {} for polling on device {}", command.getName(), deviceName);
        if (command.getPollingPeriod() != 0) {
            commandCacheMap.get(command).startRefresh(POLLING_POOL);
        }
    }
165845
public synchronized void execute(Runnable command) {
        if (active.get()) {
            stop();
            this.command = command;
            start();
        } else {
            this.command = command;
        }
    }
1207045
public synchronized void startError(final String[] args, final String execName) throws DevFailed {
        if (isStarted.get()) {
            throw DevFailedUtils.newDevFailed("this server is already started");
        }
        init(args, execName);
    }
322399
@Command(name = STATE_NAME, outTypeDesc = "Device state")
    public DevState executeStateCmd() throws DevFailed {
        MDC.setContextMap(contextMap);
        xlogger.entry();
        xlogger.exit();
        return getState();
    }
1283109
void one_more_poll() throws DevFailed {
	if (works.size() > 0) {
	    final WorkItem item = (WorkItem) works.elementAt(0);
	    works.remove(0);

	    if (polling_stop == false) {
		if (item.type == Tango_POLL_CMD) {
		    poll_cmd(item);
		} else {
		    poll_attr(item);
		}
	    }
	    item.wake_up_date = compute_new_date(item.wake_up_date, item.update);
	    insert_in_list(item);
	}
    }
844189
public void writeCommand(Command command) throws Exception {

        checkConnected();

        switch (command.getKind()) {
        case PREPARE:
            writeCommand((PrepareCommand) command);
            break;
        case START:
            writeCommand((StartCommand) command);
            break;
        case ABORT:
            writeCommand((AbortCommand) command);
            break;
        case AWAIT:
            writeCommand((AwaitCommand) command);
            break;
        case NOTIFY:
            writeCommand((NotifyCommand) command);
            break;
        case CLOSE:
            writeCommand((CloseCommand) command);
            break;
        default:
            throw new IllegalArgumentException("Urecognized command kind: " + command.getKind());
        }
    }
284275
public void restart_server() throws DevFailed {
        Util.out4.println("In DServer.restart_server() method");

        //
        // Reset initial state and status
        //

        set_state(DevState.ON);
        set_status("The device is ON");

        //
        // Destroy and recreate the muli attribute object
        //

        final MultiAttribute tmp = new MultiAttribute(device_name, get_device_class());
        set_device_attr(tmp);

        //
        // Deleting the dserver device is a specific case. We must also delete
        // all
        // TDSOM embedded in this server
        //

        if (class_list.isEmpty() == false) {

            //
            // Destroy already registered classes, devices and commands
            // To destroy already created devices, we must disconnect them from
            // the ORB
            // otherwise their reference count will never decrease to 0 and the
            // object will
            // not be eligable for garbage collection.
            //

            final int nb_class = class_list.size();
            final POA r_poa = Util.instance().get_poa();
            for (int j = 0; j < nb_class; j++) {
                final Vector v = ((DeviceClass) class_list.elementAt(j)).get_device_list();
                final int nb_dev = v.size();

                for (int k = 0; k < nb_dev; k++) {
                    final DeviceImpl dev = (DeviceImpl) v.elementAt(k);
                    if (dev.get_exported_flag() == true) {
                        dev.delete_device();
                        try {
                            r_poa.deactivate_object(((DeviceImpl) v.elementAt(k)).get_obj_id());
                        } catch (final WrongPolicy ex) {
                            ex.printStackTrace();
                        } catch (final ObjectNotActive ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                v.removeAllElements();
                ((DeviceClass) class_list.elementAt(j)).initClass();
            }
            class_list.removeAllElements();
            System.out.println("DServer.restart_server - class list " + class_list);

        }

        // Restart everything
        init_device();

        // Restart polling (if any)
        Util.instance().polling_configure();
    }
1090467
@Override
    public boolean sendCommand(String command) {
        try {
            sendCommand2(command);
        } catch (Exception ex) {
            logger.error("Could not run command " + command, ex);
            return false;
        }
        return true;
    }
345405
function runCommand(command) {
    return new Promise((resolve, reject) => {
        utils.logInfo(`Command: ${command}`);
        childProcess.exec(command, (error, stdout, stderr) => {
            // If exec returns content in stderr, but no error, print it as a warning.
            // If exec returns an error, reject the promise.
            if (error) {
                reject(error);
                return;
            } else if (stderr) {
                utils.logInfo(stderr);
            }
            resolve(stdout);
        });
    });
}
863380
private synchronized void checkInitialization() throws DevFailed {
        if (initImpl != null) {
            isInitializing = initImpl.isInitInProgress();
        } else {
            isInitializing = false;
        }
        if (isInitializing) {
            throw DevFailedUtils.newDevFailed("CONCURRENT_ERROR", name + " in Init command ");
        }
    }
620079
public void add_obj_polling(final DevVarLongStringArray argin, final boolean with_db_upd)
            throws DevFailed {
        Util.out4.println("In add_obj_polling command");
        for (final String value : argin.svalue) {
            Util.out4.println("Input string = " + value);
        }
        for (final int value : argin.lvalue) {
            Util.out4.println("Input long = " + value);
        }

        // Check that parameters number is correct
        if (argin.svalue.length != 3 || argin.lvalue.length != 1) {
            Except.throw_exception("API_WrongNumberOfArgs", "Incorrect number of inout arguments",
                    "DServer.add_obj_polling");
        }

        // Find the device
        final Util tg = Util.instance();
        DeviceImpl dev = null;
        try {
            dev = tg.get_device_by_name(argin.svalue[0]);
        } catch (final DevFailed e) {
            Except.re_throw_exception(e, "API_DeviceNotFound", "Device " + argin.svalue[0]
                    + " not found", "DServer.add_obj_polling");
        }

        // Check that the command (or the attribute) exists.
        // For command, also checks that it does not need input value.
        final String obj_type = argin.svalue[1].toLowerCase();
        final String obj_name = argin.svalue[2].toLowerCase();
        int type = Tango_POLL_CMD;
        assert dev != null;
        if (obj_type.equals(Tango_PollCommand)) {
            dev.check_command_exists(obj_name);
            type = Tango_POLL_CMD;
        } else if (obj_type.equals(Tango_PollAttribute)) {
            dev.get_device_attr().get_attr_by_name(obj_name);
            type = Tango_POLL_ATTR;
        } else {
            Except.throw_exception("API_NotSupported",
                    "Object type " + obj_type + " not supported", "DServer.add_obj_polling");
        }

        // If it's for the Init command, refuse to poll it
        if (type == Tango_POLL_CMD) {
            if (obj_name.equals("Init")) {
                Except.throw_exception("API_NotSupported",
                        "It's not possible to poll the Init command!", "DServer.add_obj_polling");
            }
        }

        // Check if the object is not already polled
        final Vector poll_list = dev.get_poll_obj_list();
        for (int i = 0; i < poll_list.size(); i++) {
            final PollObj poll_obj = (PollObj) poll_list.elementAt(i);
            if (poll_obj.get_type() == type) {
                if (poll_obj.get_name().equals(obj_name)) {
                    String s;
                    if (type == Tango_POLL_CMD) {
                        s = "Command ";
                    } else {
                        s = "Attribute ";
                    }
                    Except.throw_exception("API_AlreadyPolled", s + " " + obj_name
                            + " already polled", "DServer.add_obj_polling");
                }
            }
        }
        // Check that the update period is not to small
        final int upd = argin.lvalue[0];
        if (upd < Tango_MIN_POLL_PERIOD && upd != 0) {
            Except.throw_exception("API_NotSupported", upd
                    + " is below the min authorized period (100 mS)", "DServer.add_obj_polling");
        }

        // Create a new PollObj instance for this object
        poll_list.add(new PollObj(dev, type, obj_name, upd));

        // Send command to the polling thread but wait in case of previous cmd
        // still not executed
        Util.out4.println("Sending cmd to polling thread");
        final TangoMonitor mon = tg.get_poll_monitor();
        final PollThCmd shared_cmd = tg.get_poll_shared_cmd();

        if (shared_cmd.cmd_pending == true) {
            mon.wait_it();
        }
        shared_cmd.cmd_pending = true;
        shared_cmd.cmd_code = Tango_POLL_ADD_OBJ;
        shared_cmd.dev = dev;
        shared_cmd.index = poll_list.size() - 1;
        mon.signal();
        Util.out4.println("Cmd sent to polling thread");

        // Wait for thread to execute command
        boolean interupted;
        while (shared_cmd.cmd_pending == true) {
            interupted = mon.wait_it(Tango_DEFAULT_TIMEOUT);
            if (shared_cmd.cmd_pending == true && interupted == false) {
                Util.out4.println("TIME OUT");
                poll_list.remove(poll_list.size() - 1);
                Except.throw_exception("API_CommandTimedOut", "Polling thread blocked !!!",
                        "DServer.add_obj_polling");
            }
        }
        Util.out4.println("Thread cmd normally executed");

        // Update polling parameters in database (if wanted and possible)
        // If the property is already there (it should not but...),
        // only update its polling period
        if (with_db_upd && Util._UseDb) {
            final String upd_str = "" + upd;
            boolean found = false;

            final DbDatum db_info = new DbDatum("polled_cmd");
            if (type == Tango_POLL_CMD) {
                final Vector non_auto_list = dev.get_non_auto_polled_cmd();
                for (int i = 0; i < non_auto_list.size(); i++) {
                    final String s = (String) non_auto_list.elementAt(i);
                    if (s.equals(obj_name)) {
                        non_auto_list.remove(i);
                        db_info.name = "non_auto_polled_cmd";
                        db_info.insert(stringVect2StringArray(non_auto_list));
                        found = true;
                        break;
                    }
                }
                if (found == false) {
                    final Vector cmd_list = dev.get_polled_cmd();
                    int i;
                    for (i = 0; i < cmd_list.size(); i = i + 2) {
                        final String s = (String) cmd_list.elementAt(i);
                        if (s.equals(obj_name)) {
                            cmd_list.remove(i + 1);
                            cmd_list.insertElementAt(upd_str, i + 1);
                            break;
                        }
                    }
                    if (i == cmd_list.size()) {
                        cmd_list.add(obj_name);
                        cmd_list.add(upd_str);
                    }
                    db_info.insert(stringVect2StringArray(cmd_list));
                }
            } else {
                final Vector non_auto_list = dev.get_non_auto_polled_attr();
                for (int i = 0; i < non_auto_list.size(); i++) {
                    final String s = (String) non_auto_list.elementAt(i);
                    if (s.equals(obj_name)) {
                        non_auto_list.remove(i);
                        db_info.name = "non_auto_polled_attr";
                        db_info.insert(stringVect2StringArray(non_auto_list));
                        found = true;
                        break;
                    }
                }
                if (found == false) {
                    db_info.name = "polled_attr";
                    final Vector attr_list = dev.get_polled_attr();
                    int i;
                    for (i = 0; i < attr_list.size(); i = i + 2) {
                        final String s = (String) attr_list.elementAt(i);
                        if (s.equals(obj_name)) {
                            attr_list.remove(i + 1);
                            attr_list.insertElementAt(upd_str, i + 1);
                            break;
                        }
                    }
                    if (i == attr_list.size()) {
                        attr_list.add(obj_name);
                        attr_list.add(upd_str);
                    }
                    db_info.insert(stringVect2StringArray(attr_list));
                }
            }

            final DbDatum[] send_data = new DbDatum[1];
            send_data[0] = db_info;
            dev.get_db_device().put_property(send_data);

            Util.out4.println("Polling properties updated");
        }

        // Mark the device as polled
        dev.is_polled(true);
    }
252069
public void init(Database database, String host, String port) throws DevFailed {
        super.init(database, host, port);
    }
55568
@Override
    public Any execute(final DeviceImpl device, final Any in_any) throws DevFailed {
	Util.out4.println("InitCmd::execute(): arrived");

	// Re-initialize the device
	try {
	    device.delete_device();
	    device.init_device();
	} catch (final DevFailed e) {
	    final Util tg = Util.instance();

	    Except.re_throw_exception(e, "API_InitThrowsException", "Init command failed!!\n"
		    + "HINT: RESTART device with the Restart command"
		    + " of the device server adm. device\n"
		    + "Device server adm. device name = dserver/" + tg.get_ds_name(),
		    "InitCmd.execute()");
	}

	// return to the caller
	return Util.return_empty_any("Init");
    }
1289228
void poll_cmd(final WorkItem to_do) throws DevFailed {
	Util.out5.println("poll_cmd  --> Time = " + now.tv_sec + "," + now.tv_usec + " Dev name = "
		+ to_do.dev.get_name() + ", Cmd name = " + to_do.name);

	Any argout;
	final TimeVal before_cmd = new TimeVal();
	final TimeVal after_cmd = new TimeVal();
	TimeVal needed_time;
	try {
	    long ctm = System.currentTimeMillis();
	    before_cmd.tv_sec = (int) (ctm / 1000);
	    before_cmd.tv_usec = (int) (ctm - 1000 * before_cmd.tv_sec) * 1000;
	    before_cmd.tv_sec = before_cmd.tv_sec - Tango_DELTA_T;

	    // Execute the command
	    final Any in_any = fr.esrf.TangoApi.ApiUtil.get_orb().create_any();
	    argout = to_do.dev.command_inout(to_do.name, in_any);

	    ctm = System.currentTimeMillis();
	    after_cmd.tv_sec = (int) (ctm / 1000);
	    after_cmd.tv_usec = (int) (ctm - 1000 * after_cmd.tv_sec) * 1000;
	    after_cmd.tv_sec = after_cmd.tv_sec - Tango_DELTA_T;

	    needed_time = time_diff(before_cmd, after_cmd);

	    to_do.dev.get_dev_monitor().get_monitor();
	    final PollObj poll_obj = to_do.dev.get_polled_obj_by_type_name(to_do.type, to_do.name);
	    poll_obj.insert_data(argout, before_cmd, needed_time);
	    to_do.dev.get_dev_monitor().rel_monitor();
	} catch (final DevFailed e) {
	    final long ctm = System.currentTimeMillis();
	    after_cmd.tv_sec = (int) (ctm / 1000);
	    after_cmd.tv_usec = (int) (ctm - 1000 * after_cmd.tv_sec) * 1000;
	    after_cmd.tv_sec = after_cmd.tv_sec - Tango_DELTA_T;

	    needed_time = time_diff(before_cmd, after_cmd);

	    // to_do.dev.get_dev_monitor().get_monitor();
	    try {
		final PollObj poll_obj = to_do.dev.get_polled_obj_by_type_name(to_do.type,
			to_do.name);
		poll_obj.insert_except(e, before_cmd, needed_time);
	    } catch (final DevFailed ex) {
	    }
	    to_do.dev.get_dev_monitor().rel_monitor();
	}
    }
549664
public void insert(final Object... value) throws DevFailed {
        if (value.length == 1) {
            for (int i = 0; i < group.get_size(true); i++) {
                final int arginType = group.get_device(i + 1).command_query(commandName).in_type;
                InsertExtractUtils.insert(inData[i], arginType, value);
            }
        } else {
            if (value.length != group.get_size(true)) {
                throw DevFailedUtils.newDevFailed(TANGO_WRONG_DATA_ERROR, group.get_size(true) + " values must be provided");
            }
            for (int i = 0; i < group.get_size(true); i++) {
                final int arginType = group.get_device(i + 1).command_query(commandName).in_type;
                InsertExtractUtils.insert(inData[i], arginType, value[i]);
            }
        }
    }
292479
public Any execute(DeviceImpl device, Any in_any) throws DevFailed
	{

		Util.out4.println("PolledDeviceCmd.execute(): arrived ");

		// Call the device method and return to caller
		return insert(((DServer)(device)).polled_device());
	}
255796
def _start(self, update_cmd):
        
        try:
            self._poll(update_cmd)

        except BadStatus:
            self._operation.status = 'Failed'
            self._exception = CloudError(self._response)

        except BadResponse as err:
            self._operation.status = 'Failed'
            self._exception = CloudError(self._response, str(err))

        except OperationFailed:
            self._exception = CloudError(self._response)

        except Exception as err:
            self._exception = err

        finally:
            self._done.set()

        callbacks, self._callbacks = self._callbacks, []
        while callbacks:
            for call in callbacks:
                call(self._operation)
            callbacks, self._callbacks = self._callbacks, []