Commit 26ead10a authored by Matt Tucker's avatar Matt Tucker Committed by matt

Cleanup thread usage to use TaskEngine.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6207 b35dd754-fafc-0310-a699-88a17e54d16e
parent fffe14e6
...@@ -14,9 +14,6 @@ package org.jivesoftware.util; ...@@ -14,9 +14,6 @@ package org.jivesoftware.util;
import java.security.Security; import java.security.Security;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ArrayBlockingQueue;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.*; import javax.mail.*;
...@@ -79,16 +76,12 @@ public class EmailService { ...@@ -79,16 +76,12 @@ public class EmailService {
private boolean sslEnabled; private boolean sslEnabled;
private boolean debugEnabled; private boolean debugEnabled;
private ThreadPoolExecutor executor;
private Session session = null; private Session session = null;
/** /**
* Constructs a new EmailService instance. * Constructs a new EmailService instance.
*/ */
private EmailService() { private EmailService() {
executor = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 60,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
host = JiveGlobals.getProperty("mail.smtp.host", "localhost"); host = JiveGlobals.getProperty("mail.smtp.host", "localhost");
port = JiveGlobals.getIntProperty("mail.smtp.port", 25); port = JiveGlobals.getIntProperty("mail.smtp.port", 25);
username = JiveGlobals.getProperty("mail.smtp.username"); username = JiveGlobals.getProperty("mail.smtp.username");
...@@ -137,7 +130,7 @@ public class EmailService { ...@@ -137,7 +130,7 @@ public class EmailService {
if (messages.size() == 0) { if (messages.size() == 0) {
return; return;
} }
executor.execute(new EmailTask(messages)); TaskEngine.getInstance().submit(new EmailTask(messages));
} }
/** /**
...@@ -257,8 +250,8 @@ public class EmailService { ...@@ -257,8 +250,8 @@ public class EmailService {
* {@link #sendMessages(Collection)} in that messages are sent * {@link #sendMessages(Collection)} in that messages are sent
* before this method returns rather than queueing the messages to be sent later. * before this method returns rather than queueing the messages to be sent later.
* *
* @param messages * @param messages the messages to send.
* @throws MessagingException * @throws MessagingException if an error occurs.
*/ */
public void sendMessagesImmediately(Collection<MimeMessage> messages) public void sendMessagesImmediately(Collection<MimeMessage> messages)
throws MessagingException throws MessagingException
......
...@@ -571,9 +571,10 @@ public class XMPPServer { ...@@ -571,9 +571,10 @@ public class XMPPServer {
} }
/** /**
* Restarts the HTTP server only when running in stand alone mode. The restart process will be done * Restarts the HTTP server only when running in stand alone mode. The restart
* in another thread that will wait 1 second before doing the actual restart. The delay will give time * process will be done in another thread that will wait 1 second before doing
* to the page that requested the restart to fully render its content. * the actual restart. The delay will give time to the page that requested the
* restart to fully render its content.
*/ */
public void restartHTTPServer() { public void restartHTTPServer() {
Thread restartThread = new Thread() { Thread restartThread = new Thread() {
......
...@@ -115,7 +115,6 @@ public class GroupManager { ...@@ -115,7 +115,6 @@ public class GroupManager {
// Pre-load shared groups. This will provide a faster response // Pre-load shared groups. This will provide a faster response
// time to the first client that logs in. // time to the first client that logs in.
// TODO: use a task engine instead of creating a thread directly.
Runnable task = new Runnable() { Runnable task = new Runnable() {
public void run() { public void run() {
Collection<Group> groups = getSharedGroups(); Collection<Group> groups = getSharedGroups();
...@@ -135,9 +134,7 @@ public class GroupManager { ...@@ -135,9 +134,7 @@ public class GroupManager {
} }
} }
}; };
Thread thread = new Thread(task); TaskEngine.getInstance().submit(task);
thread.setDaemon(true);
thread.start();
} }
/** /**
......
...@@ -13,15 +13,14 @@ package org.jivesoftware.wildfire.multiplex; ...@@ -13,15 +13,14 @@ package org.jivesoftware.wildfire.multiplex;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.wildfire.*; import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.event.SessionEventDispatcher; import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.wildfire.event.SessionEventListener; import org.jivesoftware.wildfire.event.SessionEventListener;
import java.util.Collection; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
...@@ -96,28 +95,22 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -96,28 +95,22 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
sessionManager = XMPPServer.getInstance().getSessionManager(); sessionManager = XMPPServer.getInstance().getSessionManager();
// Start thread that will send heartbeats to Connection Managers every 30 seconds // Start thread that will send heartbeats to Connection Managers every 30 seconds
// to keep connections open. // to keep connections open.
Thread hearbeatThread = new Thread() { TimerTask heartbeatTask = new TimerTask() {
public void run() { public void run() {
while (true) { try {
try { for (ConnectionMultiplexerSession session : sessionManager
Thread.sleep(30000); .getConnectionMultiplexerSessions())
for (ConnectionMultiplexerSession session : sessionManager {
.getConnectionMultiplexerSessions()) { session.getConnection().deliverRawText(" ");
session.getConnection().deliverRawText(" ");
}
}
catch (InterruptedException e) {
// Do nothing
}
catch(Exception e) {
Log.error(e);
} }
} }
catch(Exception e) {
Log.error(e);
}
} }
}; };
hearbeatThread.setDaemon(true); TaskEngine.getInstance().schedule(heartbeatTask, 30*JiveConstants.SECOND,
hearbeatThread.setPriority(Thread.NORM_PRIORITY); 30*JiveConstants.SECOND);
hearbeatThread.start();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment