Package it.freedomotic.reactions

Examples of it.freedomotic.reactions.Command


     * valid
     */
    @RequiresPermissions("objects:read")
    public final Command getHardwareCommand(String action) {
        if ((action != null) && (!action.trim().isEmpty())) {
            Command commandToSearch = commandsMapping.get(action.trim().toLowerCase());

            if (commandToSearch != null) {
                return commandToSearch;
            } else {
                LOG.log(Level.SEVERE,"Doesn''t exists a valid hardware command associated to action ''{0}'' of object ''{1}"
View Full Code Here


                    getPojo().getName());

            return true;
        }

        final Command command = getHardwareCommand(action.trim());

        if (command == null) {
            LOG.log(Level.WARNING,
                    "The hardware level command for action ''{0}'' in object ''{1}'' doesn''t exists or is not setted",
                    new Object[]{action, pojo.getName()});

            return false; //command not executed
        }

        //resolves developer level command parameters like myObjectName = "@event.object.name" -> myObjectName = "Light 1"
        //in this case the parameter in the userLevelCommand are used as basis for the resolution process (the context)
        //along with the parameters getted from the relative behavior (if exists)
        LOG.log(Level.FINE,
                "Environment object ''{0}'' tries to ''{1}'' itself using hardware command ''{2}''",
                new Object[]{pojo.getName(), action, command.getName()});

        Resolver resolver = new Resolver();
        //adding a resolution context for object that owns this hardware level command. 'owner.' is the prefix of this context
        resolver.addContext("owner.",
                getExposedProperties());
        resolver.addContext("owner.",
                getExposedBehaviors());

        try {
            final Command resolvedCommand = resolver.resolve(command); //eg: turn on an X10 device
            //            XStream s = FreedomXStream.getXstream();
            //            System.out.println(s.toXML(resolvedCommand));

            Command result = busService.send(resolvedCommand); //blocking wait until timeout

            if ((result != null) && result.isExecuted()) {
                return true; //succesfully executed
            }
        } catch (CloneNotSupportedException ex) {
            Logger.getLogger(EnvObjectLogic.class.getName()).log(Level.SEVERE, null, ex);
        } catch (VariableResolutionException ex) {
View Full Code Here

            commandsMapping = new HashMap<String, Command>();
        }

        for (String action : pojo.getActions().stringPropertyNames()) {
            String commandName = pojo.getActions().getProperty(action);
            Command command = CommandPersistence.getHardwareCommand(commandName);

            if (command != null) {
                LOG.log(Level.CONFIG,
                        "Caching the command ''{0}'' as related to action ''{1}'' ",
                        new Object[]{command.getName(), action});
                setAction(action, command);
            } else {
                LOG.log(Level.CONFIG,
                        "Don''t exist a command called ''{0}'' is not possible to bound this command to action ''{1}'' of {2}",
                        new Object[]{commandName, action, this.getPojo().getName()});
View Full Code Here

    /**
     * Creates user level commands for this class of freedomotic objects
     */
    @Override
    protected void createCommands() {
        Command setOn = new Command();
        // setOn.setName(I18n.msg("turn_on_X", new Object[]{this.getPojo().getName()}));
        setOn.setName("Turn on " + getPojo().getName());
        setOn.setDescription(getPojo().getName() + " turns on");
        setOn.setReceiver("app.events.sensors.behavior.request.objects");
        setOn.setProperty("object",
                getPojo().getName());
        setOn.setProperty("behavior", BEHAVIOR_POWERED);
        setOn.setProperty("value", BooleanBehavior.VALUE_TRUE);

        Command setOff = new Command();
        // setOff.setName(I18n.msg("turn_off_X", new Object[]{this.getPojo().getName()}));
        setOff.setName("Turn off " + getPojo().getName());
        setOff.setDescription(getPojo().getName() + " turns off");
        setOff.setReceiver("app.events.sensors.behavior.request.objects");
        setOff.setProperty("object",
                getPojo().getName());
        setOff.setProperty("behavior", BEHAVIOR_POWERED);
        setOff.setProperty("value", BooleanBehavior.VALUE_FALSE);

        Command switchPower = new Command();
        // switchPower.setName(I18n.msg("switch_X_power", new Object[]{this.getPojo().getName()}));
        switchPower.setName("Switch " + getPojo().getName() + " power");
        switchPower.setDescription("switches the power of " + getPojo().getName());
        switchPower.setReceiver("app.events.sensors.behavior.request.objects");
        switchPower.setProperty("object",
                getPojo().getName());
        switchPower.setProperty("behavior", BEHAVIOR_POWERED);
        switchPower.setProperty("value", BooleanBehavior.VALUE_OPPOSITE);

        // if (CommandPersistence.getCommand(I18n.msg("turn_it_on")) == null) {
        if (CommandPersistence.getCommand("Turn it on") == null) {
            Command setItOn = new Command();
            // setItOn.setName(I18n.msg("turn_it_on"));
            setItOn.setName("Turn it on");
            setItOn.setDescription("Object turns on");
            setItOn.setReceiver("app.events.sensors.behavior.request.objects");
            setItOn.setProperty("object", "@event.object.name");
            setItOn.setProperty("behavior", BEHAVIOR_POWERED);
            setItOn.setProperty("value", "true");
            CommandPersistence.add(setItOn);
        }
       
        // if (CommandPersistence.getCommand(I18n.msg("turn_it_off")) == null) {
        if (CommandPersistence.getCommand("Turn it off") == null) {
            Command setItOff = new Command();
            // setItOff.setName(I18n.msg("turn_it_off"));
            setItOff.setName("Turn it off");
            setItOff.setDescription("Object turns off");
            setItOff.setReceiver("app.events.sensors.behavior.request.objects");
            setItOff.setProperty("object", "@event.object.name");
            setItOff.setProperty("behavior", BEHAVIOR_POWERED);
            setItOff.setProperty("value", BooleanBehavior.VALUE_FALSE);
            CommandPersistence.add(setItOff);
        }
       
        // if (CommandPersistence.getCommand(I18n.msg("switch_its_power")) == null) {
        if (CommandPersistence.getCommand("Switch its power") == null) {
            Command switchItsPower = new Command();
            // switchItsPower.setName(I18n.msg("switch_its_power"));
            switchItsPower.setName("Switch its power");
            switchItsPower.setDescription("Object switches its power");
            switchItsPower.setReceiver("app.events.sensors.behavior.request.objects");
            switchItsPower.setProperty("object", "@event.object.name");
            switchItsPower.setProperty("behavior", BEHAVIOR_POWERED);
            switchItsPower.setProperty("value", BooleanBehavior.VALUE_OPPOSITE);
            CommandPersistence.add(switchItsPower);
        }
       
        CommandPersistence.add(setOff);
        CommandPersistence.add(setOn);
View Full Code Here

        LOG.config("The gate '" + getPojo().getName() + "' connects " + from + " to " + to);
    }

    @Override
    protected void createCommands() {
        Command a = new Command();
        a.setName("Set " + getPojo().getName() + " openness to 50%");
        a.setDescription("the " + getPojo().getName() + " changes its openness");
        a.setReceiver("app.events.sensors.behavior.request.objects");
        a.setProperty("object",
                getPojo().getName());
        a.setProperty("behavior", BEHAVIOR_OPENNESS);
        a.setProperty("value", "50");

        Command b = new Command();
        b.setName("Increase " + getPojo().getName() + " openness");
        b.setDescription("increases " + getPojo().getName() + " openness of one step");
        b.setReceiver("app.events.sensors.behavior.request.objects");
        b.setProperty("object",
                getPojo().getName());
        b.setProperty("behavior", BEHAVIOR_OPENNESS);
        b.setProperty("value", "next");

        Command c = new Command();
        c.setName("Decrease " + getPojo().getName() + " openness");
        c.setDescription("decreases " + getPojo().getName() + " openness of one step");
        c.setReceiver("app.events.sensors.behavior.request.objects");
        c.setProperty("object",
                getPojo().getName());
        c.setProperty("behavior", BEHAVIOR_OPENNESS);
        c.setProperty("value", "previous");

        Command d = new Command();
        d.setName("Set its openness to 50%");
        d.setDescription("set its openness to 50%");
        d.setReceiver("app.events.sensors.behavior.request.objects");
        d.setProperty("object", "@event.object.name");
        d.setProperty("behavior", BEHAVIOR_OPENNESS);
        d.setProperty("value", "50");

        Command e = new Command();
        e.setName("Increase its openness");
        e.setDescription("increases its openness of one step");
        e.setReceiver("app.events.sensors.behavior.request.objects");
        e.setProperty("object", "@event.object.name");
        e.setProperty("behavior", BEHAVIOR_OPENNESS);
        e.setProperty("value", "next");

        Command f = new Command();
        f.setName("Decrease its openness");
        f.setDescription("decreases its openness of one step");
        f.setReceiver("app.events.sensors.behavior.request.objects");
        f.setProperty("object", "@event.object.name");
        f.setProperty("behavior", BEHAVIOR_OPENNESS);
        f.setProperty("value", "previous");

        Command g = new Command();
        g.setName("Set its openness to the value in the event");
        g.setDescription("set its openness to the value in the event");
        g.setReceiver("app.events.sensors.behavior.request.objects");
        g.setProperty("object", "@event.object.name");
        g.setProperty("behavior", BEHAVIOR_OPENNESS);
        g.setProperty("value", "@event.value");

        Command h = new Command();
        h.setName("Open " + getPojo().getName());
        h.setDescription(getPojo().getSimpleType() + " opens");
        h.setReceiver("app.events.sensors.behavior.request.objects");
        h.setProperty("object",
                getPojo().getName());
        h.setProperty("behavior", BEHAVIOR_OPEN);
        h.setProperty("value", "true");

        Command i = new Command();
        i.setName("Close " + getPojo().getName());
        i.setDescription(getPojo().getSimpleType() + " closes");
        i.setReceiver("app.events.sensors.behavior.request.objects");
        i.setProperty("object",
                getPojo().getName());
        i.setProperty("behavior", BEHAVIOR_OPEN);
        i.setProperty("value", "false");

        Command l = new Command();
        l.setName("Switch " + getPojo().getName() + " open state");
        l.setDescription("closes/opens " + getPojo().getName());
        l.setReceiver("app.events.sensors.behavior.request.objects");
        l.setProperty("object",
                getPojo().getName());
        l.setProperty("behavior", BEHAVIOR_OPEN);
        l.setProperty("value", "opposite");

        Command m = new Command();
        m.setName("Open this gate");
        m.setDescription("this gate is opened");
        m.setReceiver("app.events.sensors.behavior.request.objects");
        m.setProperty("object", "@event.object.name");
        m.setProperty("behavior", BEHAVIOR_OPEN);
        m.setProperty("value", "true");

        Command n = new Command();
        n.setName("Close this gate");
        n.setDescription("this gate is closed");
        n.setReceiver("app.events.sensors.behavior.request.objects");
        n.setProperty("object", "@event.object.name");
        n.setProperty("behavior",BEHAVIOR_OPEN);
        n.setProperty("value", "false");

        Command o = new Command();
        o.setName("Switch its open state");
        o.setDescription("opens/closes the gate in the event");
        o.setReceiver("app.events.sensors.behavior.request.objects");
        o.setProperty("object", "@event.object.name");
        o.setProperty("behavior", BEHAVIOR_OPEN);
        o.setProperty("value", "opposite");

        CommandPersistence.add(a);
        CommandPersistence.add(b);
        CommandPersistence.add(c);
        CommandPersistence.add(d);
View Full Code Here

        try {
            Object payload = message.getObject();

            if (payload instanceof Command) {
                final Command command = (Command) payload;
                LOG.info(this.getName() + " receives command " + command.getName() + " with parametes {{" + command.getProperties() + "}}");
                Runnable executorThread = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            lastDestination = message.getJMSReplyTo();
View Full Code Here

          // TODO unchecked cast!
          ObjectMessage objMessage = (ObjectMessage) jmsResponse;

          // a command is sent, we expect a command as reply
          // TODO unchecked cast!
          Command reply = (Command) objMessage.getObject();

          LOG.config("Reply to command '"
              + command.getName() + "' received. Result is "
              + reply.getProperty("result"));

          Profiler.incrementReceivedReplies();

          return reply;
View Full Code Here

            LOG.log(Level.SEVERE, null, ex);
        }

        if (jmsObject instanceof Command) {

            Command command = (Command) jmsObject;

            parseCommand(command);

            // reply to the command to notify that is received it can be
            // something like "turn on light 1"
View Full Code Here

                        /*
                         * if we have the category and the behavior (and not the
                         * object name) it means the behavior must be applied to all
                         * object belonging to the given category. eg: all lights on
                         */
                        Command clonedOne = userLevelCommand.clone();
                        applyToCategory(clonedOne);
                    } catch (CloneNotSupportedException ex) {
                        Logger.getLogger(BehaviorManager.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
View Full Code Here

    public void onMessage(ObjectMessage message) {
        try {
            Object jmsObject = message.getObject();

            if (jmsObject instanceof Command) {
                Command command = (Command) jmsObject;
                String name = command.getProperty("object.name");
                String protocol = command.getProperty("object.protocol");
                String address = command.getProperty("object.address");
                String clazz = command.getProperty("object.class");

                if (EnvObjectPersistence.getObjectByAddress(protocol, address).isEmpty()) {
                    environmentPersistence.join(clazz, name, protocol, address);
                }
            }
View Full Code Here

TOP

Related Classes of it.freedomotic.reactions.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.