Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
2017-CSE-Senior-Project-Team-2/src/utilities/AdminNotificationQueue.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
86 lines (79 sloc)
2.6 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utilities; | |
import java.sql.SQLException; | |
import java.util.Set; | |
import entities.Ticket; | |
import entities.User; | |
public class AdminNotificationQueue extends Thread { | |
/* | |
This class functions similarly to the regular notification queue. | |
There are enough differences in admin and client notifications, | |
however, that it seemed like it deserved a seperate class. | |
*/ | |
private String instructions=""; | |
private int threadWaitTime; | |
private User[] admins; | |
private Ticket[] tickets; | |
// The tickets parameter will most likely be relevant only when using this class to | |
// dispatch emails immediately with threads | |
public AdminNotificationQueue(User[] admins, String initialization, Ticket[] tickets) | |
{ | |
instructions=initialization; | |
this.admins=admins; | |
this.tickets=tickets; | |
} | |
public void run() { | |
try { | |
Thread.sleep(1); | |
} catch (InterruptedException e1) { | |
// TODO Auto-generated catch block | |
e1.printStackTrace(); | |
} | |
try { | |
String threadName = instructions; | |
Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); | |
Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); | |
boolean match = false; | |
System.out.println("Admin Notification Queue: Chacking active threads for match with "+threadName+"..."); | |
String threads = ""; | |
for (int i=0; i<threadArray.length; i++) { | |
if(threadArray[i].getName().equals(threadName)) { | |
threads+=threadArray[i].getName()+"\n"; | |
match=true; | |
} | |
} | |
System.out.println("Active threads-n"+threads+ (match ? " Found Match" : " No match")); | |
if(match){ | |
System.out.println("Redundant Admin Notification Queue thread ("+threadName+") will terminate"); | |
return; //should kill thread | |
} | |
else { | |
Thread.currentThread().setName(threadName); | |
// Finally do the thing we came for | |
switch(instructions){ | |
case "adminUrgentRequest": | |
for (User ad : admins) { | |
new Mail(ad).sendUrgentRequest(tickets); | |
} | |
break; | |
case "adminDeviceRequest": | |
queueRequestNotification(); | |
break; | |
default: | |
System.out.println("Admin notification queue could not recognize instructions"); | |
} | |
} | |
} catch(Exception e) { | |
e.printStackTrace(); | |
} finally { | |
} | |
} | |
private void queueRequestNotification() throws ClassNotFoundException, InterruptedException, SQLException { | |
threadWaitTime = 10*60000;//24*60*60*1000//frequency==1 ? 6*60*60*1000 : 24*60*60*1000; | |
Thread.sleep(threadWaitTime); | |
for(User a : admins){ | |
int notificationPreferences = a.getNotificationPreferences(); | |
boolean enabled = (notificationPreferences >> 3)==1; | |
if(enabled) new Mail(a).sendAdminSummary(threadWaitTime); | |
} | |
} | |
} |