package com.lodgon.chatserver.servlet; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; /** * ChatStore */ public class ChatStore { private static List history; private static int sequence = 0; private static Object sync = new Object(); static { history = Collections.synchronizedList(new LinkedList()); } public static void addText(String line) { System.out.println("adding text"); synchronized(sync) { history.add(line); sequence++; System.out.println("added line to history"); sync.notifyAll(); System.out.println("notified all"); } } public static boolean hasNewText(int seq) { try { while (seq >= sequence) { synchronized(sync) { sync.wait(); } } }catch(InterruptedException e) { e.printStackTrace(); } return (seq < sequence); } public static Map getNewLines(int seq) { int returnSeq = sequence; int total = sequence - seq; StringBuffer b = new StringBuffer(); for(int i = 0;i