1 package org.columba.mail.folder.outbox; 17 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Vector ; 21 22 import org.columba.mail.composer.SendableMessage; 23 24 25 31 public class SendListManager { 32 33 private static final java.util.logging.Logger LOG = 34 java.util.logging.Logger.getLogger("org.columba.mail.folder.outbox"); 36 private List sendAccounts; 37 private int counter; 38 private boolean mutex; 39 40 public SendListManager() { 41 sendAccounts = new Vector (); 42 counter = 0; 43 44 mutex = false; 45 } 46 47 private synchronized void getMutex() { 48 while (mutex) { 49 try { 50 wait(); 51 } catch (InterruptedException e) { 52 } 53 } 54 55 mutex = true; 56 } 57 58 private synchronized void releaseMutex() { 59 mutex = false; 60 notify(); 61 } 62 63 public void add(SendableMessage message) { 64 getMutex(); 65 66 SendList actList; 67 counter++; 68 69 LOG.info("SMTP_SEND::Adding message in sendlistManager"); 71 for (Iterator it = sendAccounts.iterator(); it.hasNext();) { 72 actList = (SendList) it.next(); 73 74 if (message.getAccountUid() == actList.getAccountUid()) { 78 actList.add(message); 79 releaseMutex(); 80 81 return; 82 } 83 } 84 85 sendAccounts.add(new SendList(message)); 86 87 releaseMutex(); 88 } 89 90 public boolean hasMoreMessages() { 91 getMutex(); 92 93 boolean output = (counter > 0); 94 95 releaseMutex(); 96 97 return output; 98 } 99 100 public int count() { 101 int output; 102 103 LOG.info("DEBUG"); 105 getMutex(); 106 107 output = counter; 108 109 releaseMutex(); 110 111 return output; 112 } 113 114 public Object getNextUid() { 115 getMutex(); 116 117 SendList actList = (SendList) sendAccounts.get(0); 118 Object output = actList.getFirst().getUID(); 119 120 counter--; 121 122 if (actList.count() == 0) { 123 sendAccounts.remove(0); 124 } 125 126 releaseMutex(); 127 128 return output; 129 } 130 131 public SendableMessage getNextMessage() { 132 getMutex(); 133 134 SendList actList = (SendList) sendAccounts.get(0); 135 SendableMessage output = actList.getFirst(); 136 137 counter--; 138 139 if (actList.count() == 0) { 140 sendAccounts.remove(0); 141 } 142 143 releaseMutex(); 144 145 return output; 146 } 147 } 148 149 150 class SendList { 151 private Vector messages; 152 private int accountUid; 153 154 public SendList(SendableMessage message) { 155 this.accountUid = message.getAccountUid(); 156 157 messages = new Vector (); 158 messages.add(message); 159 } 160 161 public int getAccountUid() { 162 return accountUid; 163 } 164 165 public void add(SendableMessage message) { 166 messages.add(message); 167 } 168 169 public SendableMessage getFirst() { 170 return (SendableMessage) messages.remove(0); 171 } 172 173 public SendableMessage get(int index) { 174 return (SendableMessage) messages.get(index); 175 } 176 177 public int count() { 178 return messages.size(); 179 } 180 } 181 | Popular Tags |