com.github.yoojia.events.SameThreadEvents Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of halo-events Show documentation
Show all versions of halo-events Show documentation
Tiny event bus like Guava.EventBus
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");
}
}
}