0

The AboutClient doesn´t receive the announcement

asked 2014-04-16 03:43:24 -0700

pmais gravatar image

Hi everyone,I am trying to get some properties, and an object from an About Server, this is my code:

Server side:

public class AlljoynThread extends Thread {

//variable declaration.

private BusAttachment mbus;
private String fieldname;
private Sample object;

//loading native library.

static{
    System.loadLibrary("alljoyn_java");
}

//Implementing listener class.


public class AboutStore implements PropertyStore{

    private Set < String > m_AnnounceKeys = new HashSet < String >();
    private Map < String, Map < String, Object > > m_DataMap = new HashMap <
    String, Map < String, Object > >();

    public AboutStore(Map < String, Map < String, Object > > defaultMap)
    {
    // Initialize set of Announce keys
    m_AnnounceKeys.add("AppId");
    m_AnnounceKeys.add("DefaultLanguage");
    m_AnnounceKeys.add("DeviceName");
    m_AnnounceKeys.add("DeviceId");
    m_AnnounceKeys.add("AppName");
    m_AnnounceKeys.add("Manufacturer");
    m_AnnounceKeys.add("ModelNumber");
    m_DataMap.putAll(defaultMap);

    }

    @Override
    public void readAll(String languageTag, Filter filter, Map<String, Object> dataMap)
            throws PropertyStoreException {
        // TODO Auto-generated method stub
        languageTag = checkLanguage(languageTag);
        for (Entry<String, Map<String, Object>> entry :
            m_DataMap.entrySet()) {
            if (entry.getValue().containsKey(languageTag))
            {
                String lang = "";
                if (entry.getValue().containsKey(languageTag)) {
                    lang = languageTag;
                }
                switch (filter)
                {
                case READ:
                {
                    dataMap.put(entry.getKey(),
                            entry.getValue().get(lang));
                }
                break;
                case ANNOUNCE:
                    if (m_AnnounceKeys.contains(entry.getKey()))
                    {
                        dataMap.put(entry.getKey(),
                                entry.getValue().get(lang));
                    }
                    break;
                }
            }
        }
    }   

    @Override
    public void reset(String arg0, String arg1)
            throws PropertyStoreException {
        // TODO Auto-generated method stub

    }

    @Override
    public void resetAll() throws PropertyStoreException {
        // TODO Auto-generated method stub

    }

    @Override
    public void update(String arg0, String arg1, Object arg2)
            throws PropertyStoreException {
        // TODO Auto-generated method stub

    }
    private String checkLanguage(String languageTag) throws
    PropertyStoreException
    {
    if (languageTag == null) {
    throw new
    PropertyStoreException(PropertyStoreException.INVALID_VALUE);
    }
    if (languageTag.isEmpty()) {
    return (String) m_DataMap.get("DefaultLanguage").get("");
    }
    if
    (((Set<String>)m_DataMap.get("SupportedLanguages").get("")).contains
    (languageTag)) {
    throw new
    PropertyStoreException(PropertyStoreException.UNSUPPORTED_LANGUAGE);

    }
    return languageTag;
    }


}
public class Sample implements Ping,BusObject{

    @Override
    @BusMethod
    public void Ping(String str) throws BusException {
        // TODO Auto-generated method stub

    }

    @Override
    @BusMethod
    public boolean AskDC(String serviceName) throws BusException {
        // TODO Auto-generated method stub
        return false;
    }

}

public void run(){

    Map < String, Map < String, Object >> defaultMap = new HashMap < String, Map <
            String, Object > >();


            // Populate map with fields’ names and values.
            fieldname = "DefaultLanguage";
            String languageTag = "";
            Map < String, Object > defaultValue = new HashMap <String, Object>();
            defaultValue.put("", "Value");// An empty string means non-language specific field.
            defaultMap.put(fieldname, defaultValue);
            PropertyStore aboutStore = new AboutStore(defaultMap);

    //create the bus attachment.

    mbus=new BusAttachment("AboutServer",RemoteMessage.Receive);
    object=new Sample();
    //Connect to the bus

    Status status=mbus.connect();

    if(status!=Status.OK){
        System.err.println("Failed to connect to the Alljoyn Bus");
    }

    final Mutable.ShortValue sPort = new Mutable.ShortValue((short)0);
    SessionOpts sessionOpts = new SessionOpts();
    sessionOpts.traffic = SessionOpts.TRAFFIC_MESSAGES;
    sessionOpts.isMultipoint = true;
    sessionOpts.proximity = SessionOpts.PROXIMITY_ANY;
    sessionOpts.transports = SessionOpts.TRANSPORT_ANY;

    Status status1 = mbus.bindSessionPort(sPort, sessionOpts, new
            SessionPortListener() {
            @Override
            public boolean acceptSessionJoiner(short sessionPort, String
            joiner, SessionOpts sessionOpts) {
            return true;
            }
            public void sessionJoined(short sessionPort, int id, String
            joiner){
            System.out.println("SessionPortListener.sessionJoined(%d, %d, %s)"+ sessionPort+ id+
            joiner);
            mbus.enableConcurrentCallbacks();



            }
            });
    mbus.registerBusObject(object, "/About");
    AboutService aboutService = AboutServiceImpl.getInstance();
    try {
        aboutService.startAboutServer(sPort.value, aboutStore, mbus);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mbus.advertiseName(mbus.getUniqueName(),SessionOpts.TRANSPORT_ANY);
    aboutService.announce();
    while(true){
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block ...
(more)
edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
2

answered 2014-04-23 09:30:49 -0700

pmais gravatar image

There is a problem with Hash Maps at version 1.6, I have found the solution in here:

https://github.com/joeferner/node-java/issues/50

so right now I have installed Java 1.7, and it is running without problems

Thank you everybody for your help

pmais

edit flag offensive delete publish link more

Comments

Thanks !! I had the same problem when running on ubuntu with jdk1.6.0_45, updating to jdk 1.7.0_55 solved it. This should definitely be somewhere in the doc, AFAIR the documentation suggests using java 6 (probably because of android), which does not work (at least on linux).

PierreR ( 2014-05-15 06:09:57 -0700 )edit
0

answered 2014-04-16 05:40:58 -0700

praetp gravatar image

I think this issue is answered here: https://ask.allseenalliance.org/question/179/about-service-client-in-windows-7-sdk-1402-doesnt-receive-announce-signal/

edit flag offensive delete publish link more

Comments

I have already written that line: mbus.addMatch("sessionless='t',type='error'"); It seems that the announce is getting but I receive an error message: ioeAboutServiceImplDebug: MyBusListener.nameOwnerChanged(:wxe4_KCn.1, null, :wxe4_KCn.1) ioeAboutServiceImplDebug: MyBusListener.nameOwnerChanged(org.alljoyn.sl.xwxe4_KCn.xBA, null, :wxe4_KCn.1) 71.228 ****** ERROR ALLJOYN_JAVA lepDisp ...a/jni/alljoyn_java.cc:9946 | java.lang.InternalError 71.228 ****** ERROR ALLJOYN_JAVA lepDisp ...a/jni/alljoyn_java.cc:9946 | at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:61) 71.228 ****** ERROR ALLJOYN_JAVA lepDisp ...a/jni/alljoyn_java.cc:9946 | at java.lang.reflect.Method.invoke(Method.java:588) Thank you anyway

pmais ( 2014-04-16 05:44:27 -0700 )edit
0

answered 2014-04-16 14:43:31 -0700

bspencer gravatar image

The handler has fallen out of scope:

try {

    MyAnnouncementHandler announceHandler = new MyAnnouncementHandler();
    aboutService.addAnnouncementHandler(announceHandler);
    mbus.addMatch("sessionless='t',type='error'");
    ( aboutService).startAboutClient(mbus);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Try moving the annouceHandler assignment out of the try block.

edit flag offensive delete publish link more

Comments

Hi bspencer: I have done that and I receive the same error message. I dont know what could be Thanks a lot

pmais ( 2014-04-22 00:36:04 -0700 )edit

I think that it could be something related with the implementation of the PropertyStore, because I am not familiarised with it, I have follow the steps of the usage guide but I think I am missing something. Thanks for everything

pmais ( 2014-04-22 12:09:18 -0700 )edit
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2014-04-16 03:43:24 -0700

Seen: 173 times

Last updated: Apr 23 '14