Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  5. version="3.1">
  6.  
  7. <welcome-file-list>
  8. <welcome-file>/resources/login.html</welcome-file>
  9. </welcome-file-list>
  10.  
  11. <!-- Creates the Spring Container shared by all Servlets and Filters -->
  12. <listener>
  13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  14. </listener>
  15.  
  16. <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
  17. <context-param>
  18. <param-name>contextConfigLocation</param-name>
  19. <param-value>WEB-INF/spring/root-context.xml</param-value>
  20. </context-param>
  21.  
  22. <error-page>
  23. <error-code>404</error-code>
  24. <location>/resources/login_error.html</location>
  25. </error-page>
  26.  
  27. <?xml version="1.0" encoding="UTF-8"?>
  28. <beans xmlns="http://www.springframework.org/schema/beans"
  29. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  30. xmlns:aop="http://www.springframework.org/schema/aop"
  31. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  32. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
  33.  
  34. <!-- Root Context: defines shared resources visible to all other web components -->
  35.  
  36. <bean id="mainObj" class="AppObject">
  37. <property name="filePath" value = "file:///C:/Users/A/Desktop/7_7_7"/>
  38. </bean>
  39.  
  40. <bean id="appSocketServer" class="SocketServer">
  41. <constructor-arg ref = "appModel"/>
  42. </bean>
  43.  
  44. <bean id="appModel" class = "AppModel">
  45. <constructor-arg ref = "mainObject" />
  46. </bean>
  47.  
  48. <bean id="appModelSubscribers" class= "AppModelSubscription">
  49. <constructor-arg ref = "appModelExecutor" />
  50. </bean>
  51.  
  52. <bean id="appModelExecutor" class="AppModelExecutor" scope="prototype">
  53. <constructor-arg ref = "appModelBase" />
  54. </bean>
  55.  
  56. <bean id="appModelBase" class="AppModelBase">
  57. <constructor-arg ref = "appModel" />
  58. </bean>
  59.  
  60. public class SocketServer extends Thread{
  61.  
  62. static ServerSocket ss;
  63. static Socket s;
  64. ChildServer cs;
  65. AppModel model;
  66.  
  67. public SocketServer(AppModel model) throws IOException{
  68.  
  69. this.model = model.getModel();
  70. ss = new ServerSocket(9999);
  71. }
  72.  
  73. public void run(){
  74.  
  75. while(true){
  76.  
  77. try
  78. {
  79. s = ss.accept();
  80. }
  81.  
  82. catch (IOException e1)
  83. {
  84. e1.printStackTrace();
  85. }
  86.  
  87. try
  88. {
  89. cs = new ChildServer(s, model);
  90. cs.start();
  91. }
  92.  
  93. catch (InterruptedException e)
  94. {
  95. e.printStackTrace();
  96. }
  97.  
  98. System.out.println(cs.getState());
  99. }
  100. }
  101.  
  102. public class AppModelSubscription implements Runnable{
  103.  
  104. static Set<DataListener> listenerList = new HashSet<DataListener>();
  105. volatile ArrayList<String> stmtList= new ArrayList<String>();
  106. int count = 0;
  107. AppModelExecutor exec;
  108.  
  109. public AppModelSubscription(AppModelExecutor exec){
  110.  
  111. this.exec = exec;
  112. }
  113.  
  114. public static synchronized void addlistener(DataListener listener) {
  115.  
  116. listenerList.add(listener);
  117. }
  118.  
  119. public synchronized void removeListerner(DataListener listener) {
  120.  
  121. listenerList.remove(listener);
  122. }
  123.  
  124. @Override
  125. public void run() {
  126.  
  127. TimerTask timerTask = new TimerTask() {
  128. @Override
  129. public void run() {
  130.  
  131. for(DataListener listener : listenerList)
  132. {
  133. System.out.println(listenerList.size());
  134. String stmt = listener.onData();
  135. stmtList.add(stmt);
  136.  
  137. count++;
  138. if(count == listenerList.size())
  139. count = 0;
  140. System.out.println("update from thread for data and now count is" + count);
  141. }
  142.  
  143. exec.setExecution(stmtList);
  144. exec.start();
  145. }
  146. };
  147.  
  148. Timer checkTableEntries = new Timer("checkTableEntries");
  149. checkTableEntries.schedule(timerTask, 10000, 1000);
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement