重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
一般状态的UML表示如下:
创新互联公司是专业的乌尔禾网站建设公司,乌尔禾接单;提供网站制作、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行乌尔禾网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!public enum State {
IDLE,
DATA_SOURCE,
PREPARING,
PREPARED,
STARTING,
STARTED,
BUFFERING,
READY,
SWITCHING_PROGRAM,
SWITCHING_CHANNEL,
SWITCHING_DEFINITION,
SWITCHING_ENGINE,
STOPPING,
RELEASING,
ERROR
}
状态的顺序很重要,尽量按照stack的形式,对于特殊状态特殊处理,比如error。
public class Event {
public static class SetDataSourceEvent extends LoopEvent {
public Uri uri;
public SetDataSourceEvent() {}
public SetDataSourceEvent(Uri uri) {
this.uri = uri;
}
}
public static class PrepareEvent extends LoopEvent {}
public static class StartEvent extends LoopEvent {}
public static class SwitchChannelEvent extends LoopEvent {
public int cateIndex;
public int channelIndex;
public SwitchChannelEvent() {}
public SwitchChannelEvent(int cateIndex, int channelIndex) {
this.cateIndex = cateIndex;
this.channelIndex = channelIndex;
}
}
public static class SwitchDefinitionEvent extends LoopEvent {
public int definition;
public SwitchDefinitionEvent() {}
public SwitchDefinitionEvent(int definition) {
this.definition = definition;
}
}
public static class SwitchEngineEvent extends LoopEvent {
public String engine;
public SwitchEngineEvent() {}
public SwitchEngineEvent(String engine) {
this.engine = engine;
}
}
public static class StopEvent extends LoopEvent {}
}
public abstract class Action {
protected abstract void doAction() throws Exception;
}
public class Action1 extends Action {
protected void doAction() throws Exception {
// xxxx
// update state
}
}
...
public abstract class LoopStateMachine {
private ActionThread mActionThread = new ActionThread("LoopActionThread");
private BlockingQueue mActionQueue = new ArrayBlockingQueue<>(100);
private State mState;
public void sendEvent(Event event) {
// 根据event创建action并塞入mActionQueue
}
private class ActionThread extends Thread {
public ActionThread(String name) {
super(name);
}
@Override
public void run() {
super.run();
while (true) {
try {
LoopAction action = mActionQueue.take();
action.doAction();
} catch (Exception e) {
Logger.w(TAG, "$ActionThread#run(): exception", e);
mState = State.ERROR;
// 继续
}
}
}
}
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。