Logging of device sent to logviewer device

@param deviceTargetName
@param deviceClassName
@param loggingDeviceName
@throws DevFailed
352831
public void addDeviceAppender(final String deviceTargetName, final Class<?> deviceClassName,
            final String loggingDeviceName) throws DevFailed {
        if (rootLoggerBack != null) {
            logger.debug("add device appender {} on {}", deviceTargetName, loggingDeviceName);
            final DeviceAppender appender = new DeviceAppender(deviceTargetName, loggingDeviceName);
            deviceAppenders.put(loggingDeviceName.toLowerCase(Locale.ENGLISH), appender);
            rootLoggerBack.addAppender(appender);
            // debug level by default
            setLoggingLevel(LoggingLevel.DEBUG.toInt(), deviceClassName);
            setLoggingLevel(loggingDeviceName, LoggingLevel.DEBUG.toInt());
            appender.start();
        }
    }
944252
public int get_logging_level(final DeviceProxy deviceProxy) throws DevFailed {
        // Get connection on administration device
        if (deviceProxy.getAdm_dev() == null) {
            import_admin_device(deviceProxy, "get_logging_level");
        }

        // Prepeare data
        final String[] target = new String[1];
        target[0] = get_name(deviceProxy);
        final DeviceData argin = new DeviceData();
        argin.insert(target);
        // And send command
        final DeviceData argout = deviceProxy.getAdm_dev().command_inout("GetLoggingLevel", argin);
        final DevVarLongStringArray lsa = argout.extractLongStringArray();
        return lsa.lvalue[0];
    }
570617
public void putClassPipeProperty(Database database, String className, DbPipe dbPipe) throws DevFailed {
        DeviceData argIn = new DeviceData();
        String[]    array = ApiUtil.toStringArray(className, dbPipe);
        argIn.insert(array);
        database.command_inout("DbPutClassPipeProperty", argIn);
    }
874727
public void pushAttributeDataReadyEvent(final String deviceName, final String attributeName, final int counter)
            throws DevFailed {
        xlogger.entry();
        final String fullName = EventUtilities.buildEventName(deviceName, attributeName, EventType.DATA_READY_EVENT);
        final EventImpl eventImpl = getEventImpl(fullName);
        if (eventImpl != null) {
            for (ZMQ.Socket eventSocket : eventEndpoints.values()) {
                eventImpl.pushAttributeDataReadyEvent(counter, eventSocket);
            }
        }
        xlogger.exit();
    }
319422
public String get_class(final DeviceProxy deviceProxy) throws DevFailed {
        checkIfUseDb(deviceProxy, "get_class()");
        if (deviceProxy.getDb_dev() == null) {
            deviceProxy.setDb_dev(new DbDevice(deviceProxy.devname, deviceProxy.url.host,
                deviceProxy.url.strPort));
        }
        checkIfTango(deviceProxy, "get_class");

        final String classname = super.get_class_name(deviceProxy);
        if (classname != null) {
            return classname;
        } else {
            return deviceProxy.getDb_dev().get_class();
        }
    }
97724
public void remove_logging_target (String[] dvsa) throws DevFailed {
    //- Fight against "zombie appender" synfrom
    kill_zombie_appenders();
    //- N x [device-name, ttype::tname] expected
    if ((dvsa.length % 2) != 0) {
      String desc = "Incorrect number of arguments";
      Except.throw_exception("API_MethodArgument", desc, "Logging::remove_logging_target");
    }
    //- The device name list which name match pattern
    Vector dl;
    //- For each tuple {dev-name, ttype::tname} in dvsa
    for (int t = 0; t < dvsa.length;) {
      //- Get device name pattern
      String pattern = dvsa[t++].toLowerCase();
      //- Get devices which name match the pattern
      dl = Util.instance().get_device_list(pattern);
      //- Throw exception if list is empty
      if (dl.size() == 0) {
        String desc = "No device matching pattern <" + pattern + ">";
        Except.throw_exception("API_DeviceNotFound", desc, "Logging::remove_logging_target");
      }
      //- Split type::name into target type and name
      String type = get_target_type(dvsa[t]).toLowerCase();
      String name = get_target_name(dvsa[t++]).toLowerCase();
      int type_id = LOGGING_UNKNOWN_TARGET_ID;
      if (LOGGING_FILE_TARGET.equals(type)) {
        type_id = LOGGING_FILE_TARGET_ID;
      }
      else if (LOGGING_DEVICE_TARGET.equals(type)) {
        type_id = LOGGING_DEVICE_TARGET_ID;
      }
      else if (LOGGING_CONSOLE_TARGET.equals(type)) {
        type_id = LOGGING_CONSOLE_TARGET_ID;
        name = LOGGING_CONSOLE_TARGET;
      }
      else {
        String desc = "Invalid logging target type specified (" + type + ")";
        Except.throw_exception("API_MethodArgument", desc, "Logging::remove_logging_target");
      }
      //- Remove all targets ?
      boolean remove_all_targets = name.equals("*");
      //- For each device matching pattern ...
		for (Object aDl : dl)
		{
			Logger logger = ((DeviceImpl) aDl).get_logger();
			// CASE I: remove ONE target of type <type>
			if (remove_all_targets == false)
			{
				// build full appender name
				String full_name = type + LOGGING_SEPARATOR;
				// a special case : target is the a file
				if (type_id == LOGGING_FILE_TARGET_ID)
				{
					if (name.equals(_DefaultTargetName))
					{
						//- use default path and file name
						full_name = logging_path + "/";
						full_name += device_to_file_name(logger.getName()) + ".log";
					}
					else if (name.indexOf('/') != -1)
					{
						//- user specified path and file name
						full_name = name;
					}
					else
					{
						//- user specified file name
						full_name = logging_path + "/" + name;
					}
				}
				else
				{
					full_name += name;
				}
				Util.out4.println("Removing target " + full_name + " from " + logger.getName());
				// remove appender from device's logger
				logger.removeAppender(full_name);
			}
			// CASE II: remove ALL targets of type <tg_type_str>
			else
			{
				Util.out4.println("Removing ALL <" + type + "> targets from " + logger.getName());
				// get logger's appender list
				Enumeration all_appenders = logger.getAllAppenders();
				// find appenders of type <type> in <al>
				String prefix = type + LOGGING_SEPARATOR;
				// for each appender in <al>
				while (all_appenders.hasMoreElements())
				{
					Appender appender = (Appender) all_appenders.nextElement();
					if (appender.getName().indexOf(prefix) != -1)
					{
						logger.removeAppender(appender.getName());
					}
				} // all_appenders.hasMoreElements
			} // else (if remove_all_targets)
		} // for each device in <dl>
    }
    }
1362420
public void init(final Connection connection, final String devname) throws DevFailed {
		 connection.url = new TangoUrl(devname);
		 connection.setDevice_is_dbase(false);
		 connection.devname = connection.url.devname;

		 // Check if connection is possible
		 if (connection.url.protocol == TANGO && connection.url.use_db) {
	    	 connection.ior = get_exported_ior(connection);
		 }
    }
1352155
private void class_factory() throws DevFailed {

        //
        // First, retrieve all classes embedded in this server
        //

        final Util tg = Util.instance();
        String[] cl_list = null;
        try {
            if (Util._UseDb) {
                final StringBuffer str = new StringBuffer(tg.get_ds_exec_name());
                str.append('/');
                str.append(tg.get_ds_inst_name());

                final DeviceData send = new DeviceData();
                send.insert(str.toString());
                final DeviceData received = tg.get_database().command_inout(
                        "DbGetDeviceServerClassList", send);

                cl_list = received.extractStringArray();
            } else {
                final Vector v = tg.get_class_name_list();
                cl_list = new String[v.size()];
                for (int i = 0; i < v.size(); i++) {
                    cl_list[i] = (String) v.elementAt(i);
                }
            }
        } catch (final BAD_OPERATION ex) {
            Util.out3
                    .println("DServer.class_factory() --> Wrong argument type for DbGetDeviceServerClassList command");
            Except
                    .throw_exception(
                            "API_IncompatibleCmdArgumentType",
                            "Imcompatible command argument type returned by the DbGetDeviceServerClassList command",
                            "DServer.class_factory()");
        } catch (final DevFailed ex) {
            Util.out3.println("DServer.class_factory() --> db command failed");
            Except.throw_exception("API_CantRetrieveClassList",
                    "The db command DbGetDeviceServerClassList failed", "DServer.class_factory()");
        }

        Util.out4.println(cl_list.length - 1 + " class(es) defined in server");

        //
        // Create each classes by calling its init method and store the
        // constructed
        // object in the class_list vector
        //

        int i = 0;
        try {
            for (i = 0; i < cl_list.length; i++) {

                //
                // Forget the DServer class
                //

                if (cl_list[i].equals("DServer") == true) {
                    continue;
                }

                //
                // Build the array of object used to find the init method
                //

                final Class cl_param = Class.forName("java.lang.String");
                final Class cl_param_array[] = new Class[1];
                cl_param_array[0] = cl_param;

                //
                // If there is no "Class" at the end of the class name returned
                // by the db,
                // add it and create the Class object associated with the device
                // class
                //

                Class cl;
                final int pos = cl_list[i].indexOf("Class");
                if (pos == -1) {
                    final StringBuffer class_name = new StringBuffer(cl_list[i]);
                    final int containsDot = cl_list[i].indexOf(".");
                    if (containsDot == -1) {
                        class_name.insert(0, ".");
                        class_name.append("Class");
                        class_name.insert(0, cl_list[i]);
                    } else {
                        class_name.append("Class");
                    }

                    Util.out4.println("Searching for class : " + class_name);

                    cl = Class.forName(new String(class_name));
                } else {
                    cl = Class.forName(cl_list[i]);
                }

                //
                // Retrieve the init method (which should be static) and execute
                // it
                //

                final Method init_meth = cl.getMethod("init", cl_param_array);

                final java.lang.Object[] meth_param = new java.lang.Object[1];
                final int containsDot = cl_list[i].lastIndexOf(".");
                if (containsDot == -1) {
                    meth_param[0] = cl_list[i];
                } else {
                    meth_param[0] = cl_list[i].substring(containsDot + 1);
                }
                class_list.addElement(init_meth.invoke(null, meth_param));
            }
        } catch (final ClassNotFoundException ex) {
            final StringBuffer o = new StringBuffer("Can't retrieve class ");
            o.append(cl_list[i]);
            Util.out3.println("DServer.class_factory() --> Can't find class");
            Except.throw_exception("API_ClassNotFound", new String(o), "DServer.class_factory()");
        } catch (final NoSuchMethodException ex) {
            final StringBuffer o = new StringBuffer("Can't retrieve init method in class ");
            o.append(cl_list[i]);
            Util.out3.println("DServer.class_factory() --> Can't retrieve int method");
            Except.throw_exception("API_InitMethodNotFound", new String(o),
                    "DServer.class_factory()");
        } catch (final SecurityException ex) {
            final StringBuffer o = new StringBuffer("Security exception while creating class ");
            o.append(cl_list[i]);
            Util.out3
                    .println("DServer.class_factory() --> Security exception during class creation");
            Except.throw_exception("API_JavaRuntimeSecurityException", new String(o),
                    "DServer.class_factory()");
        } catch (final InvocationTargetException ex) {
            final StringBuffer o = new StringBuffer("The init method of class ");
            o.append(cl_list[i]);
            o.append(" throws an exception");
            Util.out3
                    .println("DServer.class_factory() --> Init method send on exception during class creation");
            final Throwable th = ex.getTargetException();
            if (th instanceof fr.esrf.TangoApi.ConnectionFailed) {
                throw (fr.esrf.TangoApi.ConnectionFailed) th;
            } else if (th instanceof DevFailed) {
                throw (DevFailed) th;
            }

            Except.throw_exception("API_InitThrowsException", new String(o),
                    "DServer.class_factory()");
        } catch (final IllegalAccessException ex) {
            final StringBuffer o = new StringBuffer("The init method of class ");
            o.append(cl_list[i]);
            o.append(" is not public");
            Util.out3
                    .println("DServer.class_factory() --> Init method not accessible during class creation");
            Except.throw_exception("API_InitNotPublic", new String(o), "DServer.class_factory()");
        }
    }
1146389
public void pushAttributeValueEvent(final String deviceName, final String attributeName) throws DevFailed {
        xlogger.entry();
        for (final EventType eventType : EventType.getEventAttrValueTypeList()) {
            pushAttributeValueEventIdlLoop(deviceName, attributeName, eventType);
        }
        xlogger.exit();
    }
2410
public void delete_device_property(String name, String propname) throws DevFailed {
		databaseDAO.delete_device_property(this, name, propname);
	}
1304602
@Command(name = "SetLoggingLevel", inTypeDesc = "Lg[i]=Logging Level. Str[i]=Device name.")
    public void setLoggingLevel(final DevVarLongStringArray dvlsa) throws DevFailed {
        final int[] levels = dvlsa.lvalue;
        final String[] deviceNames = dvlsa.svalue;
        if (deviceNames.length != levels.length) {
            throw DevFailedUtils.newDevFailed(INPUT_ERROR, "argin must be of same size for string and long ");
        }
        for (int i = 0; i < levels.length; i++) {
            LoggingManager.getInstance().setLoggingLevel(deviceNames[i], levels[i]);
        }

    }
858560
public void build(final Class<?> clazz, final Field field, final DeviceImpl device, final Object businessObject)
            throws DevFailed {
        xlogger.entry();
        BuilderUtils.checkStatic(field);
        Method getter;
        final String stateName = field.getName();
        final String getterName = BuilderUtils.GET + stateName.substring(0, 1).toUpperCase(Locale.ENGLISH)
                + stateName.substring(1);
        try {
            getter = clazz.getMethod(getterName);
        } catch (final NoSuchMethodException e) {
            throw DevFailedUtils.newDevFailed(e);
        }
        if (getter.getParameterTypes().length != 0) {
            throw DevFailedUtils.newDevFailed(DevFailedUtils.TANGO_BUILD_FAILED, getter + " must not have a parameter");
        }

        logger.debug("Has an status : {}", field.getName());
        if (getter.getReturnType() != String.class) {
            throw DevFailedUtils.newDevFailed(DevFailedUtils.TANGO_BUILD_FAILED, getter + " must have a return type of  "
                    + String.class);
        }
        Method setter;
        final String setterName = BuilderUtils.SET + stateName.substring(0, 1).toUpperCase(Locale.ENGLISH)
                + stateName.substring(1);
        try {
            setter = clazz.getMethod(setterName, String.class);
        } catch (final NoSuchMethodException e) {
            throw DevFailedUtils.newDevFailed(e);
        }
        device.setStatusImpl(new StatusImpl(businessObject, getter, setter));
        final Status annot = field.getAnnotation(Status.class);
        if (annot.isPolled()) {
            device.addAttributePolling(DeviceImpl.STATUS_NAME, annot.pollingPeriod());
        }
        xlogger.exit();
    }
202967
@Override
    public void exportDevices() throws DevFailed {
        // load server class
        for (final Entry<String, Class<?>> entry : tangoClasses.entrySet()) {
            final String tangoClass = entry.getKey();
            final Class<?> deviceClass = entry.getValue();
            logger.debug("loading class {}", deviceClass.getCanonicalName());
            final DeviceClassBuilder deviceClassBuilder = new DeviceClassBuilder(deviceClass, tangoClass);
            deviceClassList.add(deviceClassBuilder);
            // export all its devices
            final String[] deviceList = DatabaseFactory.getDatabase().getDeviceList(serverName, tangoClass);
            logger.debug("devices found  {}", Arrays.toString(deviceList));
            // if (deviceList.length == 0) {
            // throw DevFailedUtils.newDevFailed(ExceptionMessages.DB_ACCESS, "No device defined in database for class "
            // + tangoClass);
            // }
            for (final String deviceName : deviceList) {
                buildDevice(deviceName, deviceClassBuilder);
            }
        }
    }
574783
public synchronized void statusMachine(final String status, final DeviceState state) throws DevFailed {
        if (status != null) {
            logger.debug("Changing status to: {}", status);
            this.status = status;
            if (setStatusMethod != null) {
                try {
                    setStatusMethod.invoke(businessObject, status);
                } catch (final IllegalArgumentException e) {
                    throw DevFailedUtils.newDevFailed(e);
                } catch (final IllegalAccessException e) {
                    throw DevFailedUtils.newDevFailed(e);
                } catch (final InvocationTargetException e) {
                    if (e.getCause() instanceof DevFailed) {
                        throw (DevFailed) e.getCause();
                    } else {
                        throw DevFailedUtils.newDevFailed(e.getCause());
                    }
                }
            }
        }
    }
315528
public void set_logging_level(final DeviceProxy deviceProxy, final int level) throws DevFailed {
        // Get connection on administration device
        if (deviceProxy.getAdm_dev() == null) {
            import_admin_device(deviceProxy, "set_logging_level");
        }

        // Prepeare data
        final DevVarLongStringArray lsa = new DevVarLongStringArray();
        lsa.lvalue = new int[1];
        lsa.svalue = new String[1];
        lsa.lvalue[0] = level;
        lsa.svalue[0] = get_name(deviceProxy);
        final DeviceData argin = new DeviceData();
        argin.insert(lsa);
        // And send command
        deviceProxy.getAdm_dev().command_inout("SetLoggingLevel", argin);
    }
481348
@Override
    protected  void checkDeviceConnection(DeviceProxy deviceProxy,
                        String attribute, DeviceData deviceData, String event_name) throws DevFailed {

        //  Check if address is coherent (??)
        deviceData = checkZmqAddress(deviceData, deviceProxy);

        String deviceName = deviceProxy.fullName();
        ApiUtil.printTrace("checkDeviceConnection for " + deviceName);
        if (!device_channel_map.containsKey(deviceName)) {
            ApiUtil.printTrace("    Does NOT Exist");
            connect(deviceProxy, attribute, event_name, deviceData);
            if (!device_channel_map.containsKey(deviceName)) {
                Except.throw_event_system_failed("API_NotificationServiceFailed",
                        "Failed to connect to event channel for device",
                        "EventConsumer.subscribe_event()");
            }
        }
        else {
            ApiUtil.printTrace(deviceName + " already connected.");
            ZMQutils.connectEvent(deviceProxy.get_tango_host(), deviceName,
                        attribute, deviceData.extractLongStringArray(), event_name,false);
        }
    }
1061978
public synchronized void stateMachine(final DeviceState state) throws DevFailed {
        if (state != null) {
            this.state = state.getDevState();
            if (setStateMethod != null) {
                logger.debug("Changing state to {}", state);
                try {
                    if (setStateMethod.getParameterTypes()[0].equals(DeviceState.class)) {
                        setStateMethod.invoke(businessObject, state);
                    } else {
                        setStateMethod.invoke(businessObject, this.state);
                    }
                } catch (final IllegalArgumentException e) {
                    throw DevFailedUtils.newDevFailed(e);
                } catch (final IllegalAccessException e) {
                    throw DevFailedUtils.newDevFailed(e);
                } catch (final InvocationTargetException e) {
                    if (e.getCause() instanceof DevFailed) {
                        throw (DevFailed) e.getCause();
                    } else {
                        throw DevFailedUtils.newDevFailed(e.getCause());
                    }
                }
            }
        }
    }