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

com.github.yoojia.events.SameThreadEvents Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package com.github.yoojia.events;

/**
 * @author YOOJIA.CHEN ([email protected])
 * @version 2015-09-10
 */
class SameThreadEvents extends AbstractEvents {

    private final long mThreadId;

    SameThreadEvents() {
        mThreadId = Thread.currentThread().getId();
    }

    @Override
    public void register(Object host) {
        checkThread();
        super.register(host);
    }

    @Override
    public void post(Object event){
        checkThread();
        super.post(event);
    }

    @Override
    public void destroy() {

    }

    private void checkThread(){
        if (mThreadId != Thread.currentThread().getId()) {
            throw new IllegalStateException("Not in the same thread");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy