/** Initializes the application */ public void init() throws ServletException { Debug.info( "******* UniTime " + Constants.getVersion() + " build on " + Constants.getReleaseDate() + " is starting up *******"); super.init(); try { Debug.info(" - Initializing Logging ... "); Debug.init(ApplicationProperties.getProperties()); Debug.info(" - Initializing Hibernate ... "); _RootDAO.initialize(); Debug.info(" - Initializing Solver Register ... "); SolverRegisterService.startService(); SolverRegisterService.addShutdownHook(); if (RoomAvailability.getInstance() != null) { Debug.info(" - Initializing Room Availability Service ... "); RoomAvailability.getInstance().startService(); } Debug.info(" - Cleaning Logs ..."); LogCleaner.cleanupLogs(); Debug.info(" - Starting Online Sectioning Service ..."); OnlineSectioningService.startService(); Debug.info( "******* UniTime " + Constants.getVersion() + " build on " + Constants.getReleaseDate() + " initialized successfully *******"); } catch (Exception e) { Debug.error("UniTime Initialization Failed : " + e.getMessage(), e); sInitializationException = e; } }
/** Terminates the application */ public void destroy() { try { Debug.info( "******* UniTime " + Constants.getVersion() + " build on " + Constants.getReleaseDate() + " is going down *******"); super.destroy(); Debug.info(" - Stopping Online Sectioning Service ..."); OnlineSectioningService.stopService(); Debug.info(" - Stopping Solver Register ... "); SolverRegisterService.stopService(); try { SolverRegisterService.removeShutdownHook(); } catch (IllegalStateException e) { } SolverInfo.stopInfoCacheCleanup(); ApplicationProperties.stopListener(); if (RoomAvailability.getInstance() != null) { Debug.info(" - Stopping Room Availability Service ... "); RoomAvailability.getInstance().stopService(); } QueueProcessor.stopProcessor(); Debug.info("******* UniTime " + Constants.getVersion() + " shut down successfully *******"); } catch (Exception e) { Debug.error("UniTime Shutdown Failed : " + e.getMessage(), e); if (e instanceof RuntimeException) throw (RuntimeException) e; else throw new RuntimeException("UniTime Shutdown Failed : " + e.getMessage(), e); } }
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ExamReportForm myForm = (ExamReportForm) form; // Check Access sessionContext.checkPermission(Right.NotAssignedExaminations); String op = (myForm.getOp() != null ? myForm.getOp() : request.getParameter("op")); if ("Export CSV".equals(op) || "Export PDF".equals(op) || "Apply".equals(op)) { myForm.save(sessionContext); } else if ("Refresh".equals(op)) { myForm.reset(mapping, request); } myForm.load(sessionContext); Session session = SessionDAO.getInstance().get(sessionContext.getUser().getCurrentAcademicSessionId()); RoomAvailability.setAvailabilityWarning(request, session, myForm.getExamType(), true, false); ExamSolverProxy solver = WebSolver.getExamSolver(request.getSession()); Collection<ExamInfo> unassignedExams = null; if (myForm.getSubjectArea() != null && myForm.getSubjectArea() != 0 && myForm.getExamType() != null) { if (solver != null && solver.getExamTypeId().equals(myForm.getExamType())) unassignedExams = solver.getUnassignedExams(myForm.getSubjectArea()); else unassignedExams = Exam.findUnassignedExams( sessionContext.getUser().getCurrentAcademicSessionId(), myForm.getSubjectArea(), myForm.getExamType()); } WebTable.setOrder(sessionContext, "unassignedExams.ord", request.getParameter("ord"), 1); WebTable table = getTable(true, false, myForm, unassignedExams); if ("Export PDF".equals(op) && table != null) { ExportUtils.exportPDF( getTable(false, true, myForm, unassignedExams), WebTable.getOrder(sessionContext, "unassignedExams.ord"), response, "unassigned"); return null; } if ("Export CSV".equals(op) && table != null) { ExportUtils.exportCSV( getTable(false, false, myForm, unassignedExams), WebTable.getOrder(sessionContext, "unassignedExams.ord"), response, "unassigned"); return null; } if (table != null) myForm.setTable( table.printTable(WebTable.getOrder(sessionContext, "unassignedExams.ord")), 9, unassignedExams.size()); if (request.getParameter("backId") != null) request.setAttribute("hash", request.getParameter("backId")); LookupTables.setupExamTypes( request, sessionContext.getUser(), DepartmentStatusType.Status.ExamTimetable); return mapping.findForward("showReport"); }
private Object answer(Object command) throws Exception { if ("quit".equals(command)) { stopConnection(); stopService(); return "ack"; } if ("ping".equals(command)) { iLastPing = System.currentTimeMillis(); if (iProxy != null && !iServers.contains(iProxy)) { sLog.warn("Server " + iProxy + " is alive, but it is not registered."); iServers.add(iProxy); } return "ack"; } if ("url".equals(command)) { return HibernateUtil.getConnectionUrl(); } if ("properties".equals(command)) { return ApplicationProperties.getProperties(); } if ("disconnect".equals(command)) { unregister(); stopConnection(); return "ack"; } if (command instanceof Object[]) { Object cmd[] = (Object[]) command; if ("connect".equals(cmd[0])) { int port = ((Integer) cmd[1]).intValue(); iProxy = new RemoteSolverServerProxy(iSocket.getInetAddress(), port, this); sLog.debug("Sever " + iProxy + " connected."); synchronized (iServers) { if (iServers.contains(iProxy)) { sLog.warn("Previous run of the server " + iProxy + " was not properly disconnected."); for (Iterator i = iServers.iterator(); i.hasNext(); ) { RemoteSolverServerProxy oldProxy = (RemoteSolverServerProxy) i.next(); if (oldProxy.equals(iProxy)) { try { execute(new DisconnectProxyCallback(oldProxy), 10000); } catch (Exception e) { } } } iServers.remove(iProxy); } iServers.add(iProxy); } return "ack"; } if ("saveToFile".equals(cmd[0])) { TimetableInfoUtil.getInstance().saveToFile((String) cmd[1], (TimetableInfo) cmd[2]); return "ack"; } if ("loadFromFile".equals(cmd[0])) { return TimetableInfoUtil.getInstance().loadFromFile((String) cmd[1]); } if ("deleteFile".equals(cmd[0])) { TimetableInfoUtil.getInstance().deleteFile((String) cmd[1]); return "ack"; } if ("resource".equals(cmd[0])) { URL resource = SolverRegisterService.class.getClassLoader().getResource((String) cmd[1]); if (resource == null) return null; ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = resource.openStream(); byte[] buffer = new byte[1024]; int read = 0; while ((read = in.read(buffer)) >= 0) out.write(buffer, 0, read); out.flush(); out.close(); in.close(); return out.toByteArray(); } if ("refreshSolution".equals(cmd[0])) { try { Solution.refreshSolution((Long) cmd[1]); } finally { _BaseRootDAO.closeCurrentThreadSessions(); } return null; } if ("hasRoomAvailability".equals(cmd[0])) { return new Boolean(RoomAvailability.getInstance() != null); } if ("activateRoomAvailability".equals(cmd[0])) { if (RoomAvailability.getInstance() != null) { RoomAvailability.getInstance() .activate( new SessionDAO().get((Long) cmd[1]), (Date) cmd[2], (Date) cmd[3], (String) cmd[4], "true" .equals( ApplicationProperties.getProperty( "tmtbl.room.availability.solver.waitForSync", "true"))); return "ack"; } return null; } if ("getRoomAvailability".equals(cmd[0])) { if (RoomAvailability.getInstance() != null) { return RoomAvailability.getInstance() .getRoomAvailability( new LocationDAO().get((Long) cmd[1]), (Date) cmd[2], (Date) cmd[3], (String) cmd[4]); } return null; } if ("getRoomAvailabilityTimeStamp".equals(cmd[0])) { if (RoomAvailability.getInstance() != null) { return RoomAvailability.getInstance() .getTimeStamp((Date) cmd[1], (Date) cmd[2], (String) cmd[3]); } return null; } } sLog.warn("Unknown command " + command); return null; }