Search in sources :

Example 1 with PlatformMessengerListener

use of com.biglybt.core.messenger.PlatformMessengerListener in project BiglyBT by BiglySoftware.

the class PlatformMessengerConfig method syncInvoke.

protected Map syncInvoke(String operationID, Map parameters, boolean forceProxy) throws PlatformMessengerException {
    PlatformMessage message = new PlatformMessage("AZMSG", listener_id, operationID, parameters, 0);
    if (!send_azid) {
        message.setSendAZID(false);
    }
    message.setForceProxy(forceProxy);
    final AESemaphore sem = new AESemaphore("PlatformMessengerConfig:syncInvoke");
    final Object[] result = { null };
    PlatformMessenger.queueMessage(message, new PlatformMessengerListener() {

        @Override
        public void messageSent(PlatformMessage message) {
        }

        @Override
        public void replyReceived(PlatformMessage message, String replyType, Map reply) {
            try {
                if (replyType.equals(PlatformMessenger.REPLY_EXCEPTION)) {
                    String e_message = (String) reply.get("message");
                    if (e_message != null) {
                        result[0] = new PlatformMessengerException(e_message);
                    } else {
                        String text = (String) reply.get("text");
                        Throwable e = (Throwable) reply.get("Throwable");
                        if (text == null && e == null) {
                            result[0] = new PlatformMessengerException("Unknown error");
                        } else if (text == null) {
                            result[0] = new PlatformMessengerException("Failed to send RPC", e);
                        } else if (e == null) {
                            result[0] = new PlatformMessengerException(text);
                        } else {
                            result[0] = new PlatformMessengerException(text, e);
                        }
                    }
                } else {
                    result[0] = reply;
                }
            } finally {
                sem.release();
            }
        }
    });
    sem.reserve();
    if (result[0] instanceof PlatformMessengerException) {
        throw ((PlatformMessengerException) result[0]);
    }
    return ((Map) result[0]);
}
Also used : PlatformMessengerException(com.biglybt.core.messenger.PlatformMessengerException) AESemaphore(com.biglybt.core.util.AESemaphore) PlatformMessengerListener(com.biglybt.core.messenger.PlatformMessengerListener) Map(java.util.Map) PlatformMessage(com.biglybt.core.messenger.PlatformMessage)

Example 2 with PlatformMessengerListener

use of com.biglybt.core.messenger.PlatformMessengerListener in project BiglyBT by BiglySoftware.

the class PlatformVuzeActivitiesMessenger method getEntries.

public static void getEntries(final long agoMS, long maxDelayMS, String reason, final GetEntriesReplyListener replyListener) {
    PlatformMessage message = new PlatformMessage("AZMSG", reason.equals("shown") ? "vznews" : LISTENER_ID, OP_GET, new Object[] { "ago-ms", new Long(agoMS), "reason", reason }, maxDelayMS);
    PlatformMessengerListener listener = null;
    if (replyListener != null) {
        listener = new PlatformMessengerListener() {

            @Override
            public void messageSent(PlatformMessage message) {
            }

            @Override
            public void replyReceived(PlatformMessage message, String replyType, Map reply) {
                ActivitiesEntry[] entries = new ActivitiesEntry[0];
                List entriesList = (List) MapUtils.getMapObject(reply, "entries", null, List.class);
                if (entriesList != null && entriesList.size() > 0) {
                    entries = new ActivitiesEntry[entriesList.size()];
                    int i = 0;
                    for (Iterator iter = entriesList.iterator(); iter.hasNext(); ) {
                        Map platformEntry = (Map) iter.next();
                        if (platformEntry == null) {
                            continue;
                        }
                        entries[i] = ActivitiesManager.createEntryFromMap(platformEntry, false);
                        if (entries[i] != null) {
                            i++;
                        }
                    }
                }
                long refreshInMS = MapUtils.getMapLong(reply, "refresh-in-ms", DEFAULT_RETRY_MS);
                replyListener.gotVuzeNewsEntries(entries, refreshInMS);
            }
        };
    }
    PlatformMessenger.queueMessage(message, listener);
}
Also used : ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) Iterator(java.util.Iterator) List(java.util.List) PlatformMessengerListener(com.biglybt.core.messenger.PlatformMessengerListener) Map(java.util.Map) PlatformMessage(com.biglybt.core.messenger.PlatformMessage)

Aggregations

PlatformMessage (com.biglybt.core.messenger.PlatformMessage)2 PlatformMessengerListener (com.biglybt.core.messenger.PlatformMessengerListener)2 Map (java.util.Map)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1 PlatformMessengerException (com.biglybt.core.messenger.PlatformMessengerException)1 AESemaphore (com.biglybt.core.util.AESemaphore)1 Iterator (java.util.Iterator)1 List (java.util.List)1