package de.ugoe.cs.eventbench.web.commands; import java.io.File; import java.io.FileReader; import java.security.InvalidParameterException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import de.ugoe.cs.eventbench.data.Event; import de.ugoe.cs.eventbench.web.data.WebEvent; import de.ugoe.cs.util.console.Command; import de.ugoe.cs.util.console.Console; public class CMDloadSessionsFromClickstream implements Command { @Override public void run(List parameters) { // TODO Auto-generated method stub if( parameters.size() < 2 ) { throw new InvalidParameterException(); } String source = (String) parameters.get(0); // TODO needs to be variable long timeout = 3600000; // 1 hour session-timeout try { // TODO dummy try/catch block File f = new File(source); FileReader reader = new FileReader(f); char[] buffer = new char[(int) f.length()]; reader.read(buffer); reader.close(); String[] lines = (new String(buffer)).split("\n"); Map> cookieSessionMap = new HashMap>(); int lastId = -1; List> sessions = new ArrayList>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for( int i=0; i sessionIds = cookieSessionMap.get(cookie); if( sessionIds==null ) { sessionIds = new ArrayList(); // start new session sessionIds.add(++lastId); cookieSessionMap.put(cookie, sessionIds); sessions.add(new LinkedList()); } Integer lastSessionIndex = sessionIds.get(sessionIds.size()-1); List lastSession = sessions.get(lastSessionIndex); long lastEventTime = timestamp; if( !lastSession.isEmpty() ) { lastEventTime = lastSession.get(lastSession.size()-1).getTimestamp(); } if( timestamp-lastEventTime>timeout ) { sessionIds.add(++lastId); List newSession = new LinkedList(); newSession.add(new WebEvent(uri, timestamp)); sessions.add(newSession); } else { lastSession.add(new WebEvent(uri, timestamp)); } } Console.traceln(sessions.toString()); } catch(Exception e) { e.printStackTrace(); } } @Override public void help() { // TODO Auto-generated method stub } }