Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
- version="3.1">
- <welcome-file-list>
- <welcome-file>/resources/login.html</welcome-file>
- </welcome-file-list>
- <!-- Creates the Spring Container shared by all Servlets and Filters -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>WEB-INF/spring/root-context.xml</param-value>
- </context-param>
- <error-page>
- <error-code>404</error-code>
- <location>/resources/login_error.html</location>
- </error-page>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
- <!-- Root Context: defines shared resources visible to all other web components -->
- <bean id="mainObj" class="AppObject">
- <property name="filePath" value = "file:///C:/Users/A/Desktop/7_7_7"/>
- </bean>
- <bean id="appSocketServer" class="SocketServer">
- <constructor-arg ref = "appModel"/>
- </bean>
- <bean id="appModel" class = "AppModel">
- <constructor-arg ref = "mainObject" />
- </bean>
- <bean id="appModelSubscribers" class= "AppModelSubscription">
- <constructor-arg ref = "appModelExecutor" />
- </bean>
- <bean id="appModelExecutor" class="AppModelExecutor" scope="prototype">
- <constructor-arg ref = "appModelBase" />
- </bean>
- <bean id="appModelBase" class="AppModelBase">
- <constructor-arg ref = "appModel" />
- </bean>
- public class SocketServer extends Thread{
- static ServerSocket ss;
- static Socket s;
- ChildServer cs;
- AppModel model;
- public SocketServer(AppModel model) throws IOException{
- this.model = model.getModel();
- ss = new ServerSocket(9999);
- }
- public void run(){
- while(true){
- try
- {
- s = ss.accept();
- }
- catch (IOException e1)
- {
- e1.printStackTrace();
- }
- try
- {
- cs = new ChildServer(s, model);
- cs.start();
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- System.out.println(cs.getState());
- }
- }
- public class AppModelSubscription implements Runnable{
- static Set<DataListener> listenerList = new HashSet<DataListener>();
- volatile ArrayList<String> stmtList= new ArrayList<String>();
- int count = 0;
- AppModelExecutor exec;
- public AppModelSubscription(AppModelExecutor exec){
- this.exec = exec;
- }
- public static synchronized void addlistener(DataListener listener) {
- listenerList.add(listener);
- }
- public synchronized void removeListerner(DataListener listener) {
- listenerList.remove(listener);
- }
- @Override
- public void run() {
- TimerTask timerTask = new TimerTask() {
- @Override
- public void run() {
- for(DataListener listener : listenerList)
- {
- System.out.println(listenerList.size());
- String stmt = listener.onData();
- stmtList.add(stmt);
- count++;
- if(count == listenerList.size())
- count = 0;
- System.out.println("update from thread for data and now count is" + count);
- }
- exec.setExecution(stmtList);
- exec.start();
- }
- };
- Timer checkTableEntries = new Timer("checkTableEntries");
- checkTableEntries.schedule(timerTask, 10000, 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement