Add attribute polling

@param attributeName the attribute to poll
@param pollingPeriod the polling period
@throws DevFailed
498889
public void addAttributePolling(final String attributeName, final int pollingPeriod) throws DevFailed {

        logger.debug("add {} polling with period {}", attributeName, pollingPeriod);
        checkPollingLimits(attributeName, pollingPeriod, minAttributePolling);
        final AttributeImpl attribute = AttributeGetterSetter.getAttribute(attributeName, attributeList);
        if (attribute.getBehavior() instanceof ForwardedAttribute) {
            throw DevFailedUtils.newDevFailed(attributeName + " not pollable because it is a forwarded attribute");
        }
        attribute.configurePolling(pollingPeriod);
        if (attribute.getName().equals(DeviceImpl.STATE_NAME) || attribute.getName().equals(DeviceImpl.STATUS_NAME)) {
            // command is also set as polled
            final CommandImpl cmd = CommandGetter.getCommand(attribute.getName(), commandList);
            cmd.configurePolling(pollingPeriod);
            cacheManager.startStateStatusPolling(cmd, attribute);
        } else {
            cacheManager.startAttributePolling(attribute);
        }
        pollAttributes.put(attributeName.toLowerCase(Locale.ENGLISH), pollingPeriod);
        savePollingConfig();
    }
1054730
public void addTangoInterfaceChangeListener(ITangoInterfaceChangeListener listener, String attrName)
            throws DevFailed {
        addTangoInterfaceChangeListener(listener, attrName, false);
    }
606124
public int write_attribute_asynch(final DeviceProxy deviceProxy,
	    final DeviceAttribute[] attribs, final boolean forget) throws DevFailed {

		build_connection(deviceProxy);

		//
		// Manage Access control
		//
		if (deviceProxy.access == TangoConst.ACCESS_READ) {
	    	// pind the device to throw execption
	    	// if failed (for reconnection)
	    	ping(deviceProxy);

        	throwNotAuthorizedException(deviceProxy.devname + ".write_attribute_asynch()",
		    	"DeviceProxy.write_attribute_asynch()");
		}

		// Build idl argin object
		Request request;
		final String[] attributeNames = new String[attribs.length];

		Any any;
		if (deviceProxy.device_5 != null || deviceProxy.device_4 != null) {
	    	final AttributeValue_4[] attributeValues_4 = new AttributeValue_4[attribs.length];
	    	for (int i=0; i<attribs.length ; i++) {
                attributeValues_4[i] = attribs[i].getAttributeValueObject_4();
                attributeValues_4[i].err_list = new DevError[0];
                attributeNames[i] = attributeValues_4[i].name;
            }
	    	request = deviceProxy.device_4._request("write_attributes_4");

	    	any = request.add_in_arg();
	    	AttributeValueList_4Helper.insert(any, attributeValues_4);

	    	any = request.add_in_arg();
	    	ClntIdentHelper.insert(any, DevLockManager.getInstance().getClntIdent());
	    	request.exceptions().add(MultiDevFailedHelper.type());
		}
        else {
	    	final AttributeValue[] attributeValues = new AttributeValue[attribs.length];
	    	for (int i = 0; i < attribs.length; i++) {
			    attributeValues[i] = attribs[i].getAttributeValueObject_2();
			    attributeNames[i] = attributeValues[i].name;
	    	}

	    	// Create the request object
	    	if (deviceProxy.device_3 != null) {
			    request = deviceProxy.device_3._request("write_attributes_3");
	    	}
            else if (deviceProxy.device_2 != null) {
	    		request = deviceProxy.device_2._request("write_attributes");
	    	}
            else {
    			request = deviceProxy.device._request("write_attributes");
	    	}

	    	any = request.add_in_arg();
	    	AttributeValueListHelper.insert(any, attributeValues);
		}

		request.exceptions().add(DevFailedHelper.type());

		// send it (defered or just one way)

		int id = 0;
		boolean done = false;
		// try 2 times for reconnection if requested
		final int retries = deviceProxy.transparent_reconnection ? 2 : 1;
		for (int i=0 ; i<retries && !done ; i++) {
	    	try {
                if (forget) {
                    request.send_oneway();
                } else {
                    request.send_deferred();
                    // store request reference to read reply later
                    id = ApiUtil.put_async_request(new AsyncCallObject(request, deviceProxy, ATT_W,
                        attributeNames));
                }
                done = true;
	    	} catch (final Exception e) {
                manageExceptionReconnection(deviceProxy,
                        retries, i, e, this.getClass() + ".write_attribute_asynch");
	    	}
		}
		return id;
    }
849493
synchronized String[] dev_poll_status(final String dev_name) throws DevFailed {
        Util.out4.println("In dev_poll_status command");

        // Find the device
        final DeviceImpl dev = Util.instance().get_device_by_name(dev_name);

        final Vector poll_list = dev.get_poll_obj_list();
        final int nb_poll_obj = poll_list.size();

        // Return an empty sequence if nothing is polled for this device
        if (nb_poll_obj == 0) {
            return new String[0];
        }

        // Compute how many cmds and/or attributes are polled
        int nb_cmd = 0;
        for (int i = 0; i < nb_poll_obj; i++) {
            final PollObj poll_obj = (PollObj) poll_list.elementAt(i);
            if (poll_obj.get_type() == Tango_POLL_CMD) {
                nb_cmd++;
            }
        }

        // Allocate memory for returned strings
        final String[] ret = new String[nb_poll_obj];

        // Populate returned strings
        int cmd_ind = 0;
        int attr_ind = nb_cmd;
        String returned_info;

        for (int i = 0; i < nb_poll_obj; i++) {
            final PollObj poll_obj = (PollObj) poll_list.elementAt(i);
            // First, the name
            final int type = poll_obj.get_type();
            if (type == Tango_POLL_CMD) {
                returned_info = "Polled command name = ";
            } else {
                returned_info = "Polled attribute name = ";
            }
            returned_info += poll_obj.get_name();

            // Add update period
            returned_info += "\nPolling period (mS) = ";
            final int tmp = poll_obj.get_upd();
            returned_info = returned_info + tmp;

            // Add ring buffer depth
            returned_info += "\nPolling ring buffer depth = ";
            final int depth = dev.get_poll_ring_depth();
            if (depth == 0) {
                returned_info += Tango_DefaultPollRingDepth;
            } else {
                returned_info += depth;
            }

            // Add a message if the data ring is empty
            if (poll_obj.is_ring_empty() == true) {
                returned_info += "\nNo data recorded yet";
            } else {
                // Add needed time to execute last command
                returned_info += "\nTime needed for the last ";
                if (type == Tango_POLL_CMD) {
                    returned_info += "command execution (mS) = ";
                } else {
                    returned_info += "attribute reading (mS) = ";
                }
                returned_info += poll_obj.get_needed_time_i();

                // Add not updated since... info
                returned_info += "\nData not updated since ";
                final double since = poll_obj.get_last_insert_date_i();

                final long ctm = System.currentTimeMillis();
                final int tv_sec = (int) (ctm / 1000);
                final int tv_usec = (int) (ctm - 1000 * tv_sec) * 1000;

                final double now_d = tv_sec + (double) tv_usec / 1000000;
                final double diff_t = now_d - since;
                if (diff_t < 1.0) {
                    final int nb_msec = (int) (diff_t * 1000);
                    returned_info = returned_info + nb_msec + " mS";
                } else if (diff_t < 60.0) {
                    final int nb_sec = (int) diff_t;
                    final int nb_msec = (int) ((diff_t - nb_sec) * 1000);
                    returned_info = returned_info + nb_sec + " S and ";
                    returned_info = returned_info + nb_msec + " mS";
                } else {
                    final int nb_min = (int) (diff_t / 60);
                    final int nb_sec = (int) (diff_t - 60 * nb_min);
                    final int nb_msec = (int) ((diff_t - (int) diff_t) * 1000);

                    returned_info = returned_info + nb_min + " MN";

                    if (nb_sec != 0) {
                        returned_info = returned_info + " ," + nb_sec + " S";
                    }

                    if (nb_msec != 0) {
                        returned_info = returned_info + " and " + nb_msec + " mS";
                    }
                }

                // Add delta_t between last record(s)
                try {
                    returned_info += "\nDelta between last records (in mS) = ";
                    final double[] delta = poll_obj.get_delta_t_i(4);
                    for (int j = 0; j < delta.length; j++) {
                        final int nb_msec = (int) (delta[j] * 1000);
                        returned_info = returned_info + nb_msec;
                        if (j != delta.length - 1) {
                            returned_info = returned_info + ", ";
                        }
                    }
                } catch (final DevFailed e) {
                }

                // Add last polling exception fields (if any)
                if (poll_obj.is_last_an_error_i() == true) {
                    if (type == Tango_POLL_CMD) {
                        returned_info += "\nLast command execution FAILED :";
                    } else {
                        returned_info += "\nLast attribute read FAILED :";
                    }
                    final DevFailed ex = poll_obj.get_last_except_i();
                    returned_info += "\n\tReason = " + ex.errors[0].reason;
                    returned_info += "\n\tDesc = " + ex.errors[0].desc;
                    returned_info += "\n\tOrigin = " + ex.errors[0].origin;
                }
            }

            // Init. string in sequence
            if (type == Tango_POLL_CMD) {
                ret[cmd_ind] = returned_info;
                cmd_ind++;
            } else {
                ret[attr_ind] = returned_info;
                attr_ind++;
            }
        }
        return ret;
    }
452547
public void remove_attribute(final String attname) throws DevFailed {
	// Remove property in database
	if (Util._UseDb) {
	    final DeviceProxy dev = new DeviceProxy(device_name);
	    final DbAttribute da = dev.get_attribute_property(attname);
	    dev.delete_attribute_property(da);

	}
	dev_attr.remove_attribute(attname);
    }
576220
public void write_attribute_asynch(final DeviceProxy deviceProxy, final DeviceAttribute attr,
	    final CallBack cb) throws DevFailed {
        final DeviceAttribute[] attribs = new DeviceAttribute[1];
        attribs[0] = attr;
        write_attribute_asynch(deviceProxy, attribs, cb);
    }
974944
public void put_property(DbDatum property)
            throws DevFailed {
        DbAttribute db_att = new DbAttribute(deviceName);
        db_att.add(property);
        dev.put_attribute_property(db_att);
    }
1303407
public void addTangoDataReadyListener(ITangoDataReadyListener listener, String attrName, boolean stateless)
            throws DevFailed {
        addTangoDataReadyListener(listener, attrName, new String[0], stateless);
    }
881980
public void poll_attribute(final DeviceProxy deviceProxy, final String attname, final int period)
	    throws DevFailed {
    	poll_object(deviceProxy, attname, "attribute", period);
    }
608014
private synchronized void add(final String... attributes) throws DevFailed {
        userAttributesNames = new String[attributes.length];
        devices = new DeviceProxy[attributes.length];
        int i = 0;
        for (final String attributeName : attributes) {
            final String deviceName = TangoUtil.getfullDeviceNameForAttribute(attributeName)
                    .toLowerCase(Locale.ENGLISH);
            final String fullAttribute = TangoUtil.getfullAttributeNameForAttribute(attributeName).toLowerCase(
                    Locale.ENGLISH);
            userAttributesNames[i] = fullAttribute;
            try {
                final DeviceProxy device = ProxyFactory.getInstance().createDeviceProxy(deviceName);
                devices[i++] = device;
                if (!devicesMap.containsKey(deviceName)) {
                    devicesMap.put(deviceName, device);
                }
            } catch (final DevFailed e) {
                if (throwExceptions) {
                    throw e;
                } else {
                    devices[i++] = null;
                    if (!devicesMap.containsKey(deviceName)) {
                        devicesMap.put(deviceName, null);
                    }
                }
            }
            final String attribute = fullAttribute.split("/")[3];
            if (!attributesMap.containsKey(deviceName)) {
                final List<String> attributesNames = new ArrayList<String>();
                attributesNames.add(attribute);
                attributesMap.put(deviceName, attributesNames);
            } else {
                attributesMap.get(deviceName).add(attribute);
            }
        }
    }
1314776
public void addTangoPeriodicListener(ITangoPeriodicListener listener, String attrName, String[] filters, boolean stateless)
            throws DevFailed {
        TangoPeriodic tangoPeriodic;

        String key = deviceName+"/"+attrName;
        if ((tangoPeriodic = tango_periodic_source.get(key)) == null) {
            tangoPeriodic = new TangoPeriodic(deviceProxy, attrName, filters);
            tango_periodic_source.put(key, tangoPeriodic);
        }

        synchronized (moni) {
            tangoPeriodic.addTangoPeriodicListener(listener, stateless);
        }
    }
112194
public synchronized void addAttribute(final AttributeImpl attribute) throws DevFailed {
        // add attribute only if it doesn't exists
        AttributeImpl result = null;
        for (final AttributeImpl attr : attributeList) {
            if (attr.getName().equalsIgnoreCase(attribute.getName())) {
                result = attribute;
                break;
            }
        }
        if (result == null) {
            attributeList.add(attribute);
            // set default polling configuration
            if (attrPollRingDepth.containsKey(attribute.getName().toLowerCase(Locale.ENGLISH))) {
                attribute.setPollRingDepth(attrPollRingDepth.get(attribute.getName().toLowerCase(Locale.ENGLISH)));
            } else {
                attribute.setPollRingDepth(pollRingDepth);
            }
        }
    }
1191196
public void put_attribute_alias(String attname, String aliasname) throws DevFailed {
		databaseDAO.put_attribute_alias(this, attname, aliasname);
	}
1118168
@Override
    public Map<String, String[]> getAttributeProperties(final String deviceName, final String attributeName)
            throws DevFailed {
        Map<String, String[]> map;
        final DeviceData argin = new DeviceData();
        final List<String> args = new ArrayList<String>();
        args.add(deviceName);
        args.add(attributeName);
        // value is an array
        argin.insert(args.toArray(new String[args.size()]));
        final DeviceData argout = database.command_inout("DbGetDeviceAttributeProperty2", argin);
        final String[] result = argout.extractStringArray();
        map = extractArgout(result, 4);
        return map;

    }
529454
public DbAttribute get_device_attribute_property(String devname, String attname) throws DevFailed {
		return databaseDAO.get_device_attribute_property(this, devname, attname);
	}
160746
static byte[] marshallIDL4(final AttributeImpl attribute) throws DevFailed {
        XLOGGER.entry();
        final AttributeValue_4 attributeValue = TangoIDLAttributeUtil.toAttributeValue4(attribute,
                attribute.getReadValue(), attribute.getWriteValue());
        return marshallIDL4(attributeValue);
    }
286322
public void addTangoUserListener(ITangoUserListener listener, String attrName, boolean stateless)
            throws DevFailed {
        addTangoUserListener(listener, attrName, new String[0], stateless);
    }