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

org.robokind.client.basic.RkAccelerometerConnector Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2013 Hanson Robokind LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.robokind.client.basic;

import java.net.URISyntaxException;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Session;
import org.jflux.api.core.util.EmptyAdapter;
import org.jflux.api.messaging.rk.MessageAsyncReceiver;
import org.jflux.api.messaging.rk.MessageSender;
import org.robokind.api.sensor.AccelerometerConfigEvent;
import org.robokind.api.sensor.DeviceReadPeriodEvent;
import org.robokind.api.sensor.FilteredVector3Event;
import org.robokind.api.sensor.imu.RemoteAccelerometerServiceClient;
import org.robokind.client.basic.ConnectionContext.RkServiceConnector;
import org.robokind.impl.sensor.AccelerometerConfigRecord;
import org.robokind.impl.sensor.DeviceReadPeriodRecord;
import org.robokind.impl.sensor.FilteredVector3Record;
import org.robokind.impl.sensor.HeaderRecord;

/**
 *
 * @author Jason G. Pallack 
 */
final class RkAccelerometerConnector extends RkServiceConnector{
    final static String ACCEL_VALUE_RECEIVER = "accelValueReceiver";
    final static String ACCEL_CONFIG_SENDER = "accelConfigSender";
    final static String ACCEL_READ_PERIOD_SENDER = "accelReadPeriodSender";
    
    private static RkAccelerometerConnector theRkAccelerometerConnector;
    
    private String theAccelInputDest = "accelerometerEvent";
    private String theAccelConfigDest = "accelerometerConfig";
    private String theAccelReadDest = "accelerometerRead";
    
    static synchronized RkAccelerometerConnector getConnector(){
        if(theRkAccelerometerConnector == null){
            theRkAccelerometerConnector = new RkAccelerometerConnector();
        }
        return theRkAccelerometerConnector;
    }
    
    @Override
    protected synchronized void addConnection(Session session) 
            throws JMSException, URISyntaxException{
        if(myConnectionContext == null || myConnectionsFlag){
            return;
        }
        Destination accelValReceiver = ConnectionContext.getTopic(theAccelInputDest);
        myConnectionContext.addAsyncReceiver(ACCEL_VALUE_RECEIVER, session, accelValReceiver,
                FilteredVector3Record.class, FilteredVector3Record.SCHEMA$,
                new EmptyAdapter());
        Destination accelCfgSender = ConnectionContext.getTopic(theAccelConfigDest);
        myConnectionContext.addSender(ACCEL_CONFIG_SENDER, session, accelCfgSender, 
                new EmptyAdapter());
        Destination accelPerSender = ConnectionContext.getTopic(theAccelReadDest);
        myConnectionContext.addSender(ACCEL_READ_PERIOD_SENDER, session, accelPerSender, 
                new EmptyAdapter());
        myConnectionsFlag = true;
    }
    
    synchronized RemoteAccelerometerServiceClient buildRemoteClient() {
        if(myConnectionContext == null || !myConnectionsFlag){
            return null;
        }
        MessageAsyncReceiver accelValReceiver = 
                myConnectionContext.getAsyncReceiver(ACCEL_VALUE_RECEIVER);
        MessageSender> accelCfgSender = 
                myConnectionContext.getSender(ACCEL_CONFIG_SENDER);
        MessageSender> accelPerSender = 
                myConnectionContext.getSender(ACCEL_READ_PERIOD_SENDER);
        
        RemoteAccelerometerServiceClient client =
                new RemoteAccelerometerServiceClient(
                accelCfgSender, accelPerSender, accelValReceiver);
        return client;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy