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

io.femo.http.events.HttpEventManager Maven / Gradle / Ivy

Go to download

An easy to use HTTP API, that supports synchronous and asynchronous execution of HTTP request. On android only asynchronous driver is supported. This library has been backported to jdk 7 to retain compatibility with android!

The newest version!
package io.femo.http.events;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by felix on 2/11/16.
 */
public class HttpEventManager {

    private Map> events;

    public HttpEventManager () {
        events = new HashMap<>();
    }

    public void raise(HttpEvent event) {
        if(events.containsKey(event.eventType())) {
            List handlers = events.get(event.eventType());
            for (HttpEventHandler handler: handlers) {
                try {
                    handler.handle(event);
                } catch (Throwable t) {
                    System.err.println("Error while handling event " + event + ".");
                }
            }
        }
    }

    public void addEventHandler(HttpEventType type, HttpEventHandler handler) {
        if(type == HttpEventType.ALL) {
            for (HttpEventType t : HttpEventType.values()) {
                if(t == HttpEventType.ALL)
                    continue;
                addEventHandler(t, handler);
            }
        } else {
            if(!events.containsKey(type)) {
                events.put(type, new ArrayList());
            }
            events.get(type).add(handler);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy