01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.getahead.dwrdemo.gidemo;
17:
18: import java.util.Collection;
19: import java.util.concurrent.ScheduledThreadPoolExecutor;
20: import java.util.concurrent.TimeUnit;
21:
22: import org.directwebremoting.ScriptSession;
23: import org.directwebremoting.ServerContext;
24: import org.directwebremoting.ServerContextFactory;
25: import org.directwebremoting.proxy.ScriptProxy;
26: import org.directwebremoting.util.SharedObjects;
27:
28: /**
29: * A generator of random objects to push to GI
30: * @author Joe Walker [joe at getahead dot ltd dot uk]
31: */
32: public class Publisher implements Runnable {
33: /**
34: * Create a new publish thread and start it
35: */
36: public Publisher() {
37: ScheduledThreadPoolExecutor executor = SharedObjects
38: .getScheduledThreadPoolExecutor();
39: executor.scheduleAtFixedRate(this , 1, 1, TimeUnit.SECONDS);
40: }
41:
42: /* (non-Javadoc)
43: * @see java.lang.Runnable#run()
44: */
45: public void run() {
46: ServerContext serverContext = ServerContextFactory.get();
47: String contextPath = serverContext.getContextPath();
48: if (contextPath == null) {
49: return;
50: }
51:
52: Collection<ScriptSession> sessions = serverContext
53: .getScriptSessionsByPage(contextPath
54: + "/gi/dwr-oa-gi.html");
55: ScriptProxy proxy = new ScriptProxy(sessions);
56:
57: Corporation corp = corporations.getNextChangedCorporation();
58: proxy.addFunctionCall("OpenAjax.hub.publish", "gidemo.corp",
59: corp);
60: }
61:
62: /**
63: * The set of corporations that we manage
64: */
65: protected Corporations corporations = new Corporations();
66: }
|