Java 类javax.mail.event.TransportListener 实例源码

项目:javamail    文件:SmtpJmsTransportTest.java   
@Before
public void setUp() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestContextFactory.class.getName());
    QueueConnectionFactory queueConnectionFactory = Mockito.mock(QueueConnectionFactory.class);
    Queue queue = Mockito.mock(Queue.class);
    Context context = Mockito.mock(Context.class);
    TestContextFactory.context = context;
    when(context.lookup(eq("jms/queueConnectionFactory"))).thenReturn(queueConnectionFactory);
    when(context.lookup(eq("jms/mailQueue"))).thenReturn(queue);
    queueSender = Mockito.mock(QueueSender.class);
    QueueConnection queueConnection = Mockito.mock(QueueConnection.class);
    when(queueConnectionFactory.createQueueConnection()).thenReturn(queueConnection);
    when(queueConnectionFactory.createQueueConnection(anyString(), anyString())).thenReturn(queueConnection);
    QueueSession queueSession = Mockito.mock(QueueSession.class);
    bytesMessage = Mockito.mock(BytesMessage.class);
    when(queueSession.createBytesMessage()).thenReturn(bytesMessage);
    when(queueConnection.createQueueSession(anyBoolean(), anyInt())).thenReturn(queueSession);
    when(queueSession.createSender(eq(queue))).thenReturn(queueSender);
    transport = new SmtpJmsTransport(Session.getDefaultInstance(new Properties()), new URLName("jms"));
    transportListener = Mockito.mock(TransportListener.class);
    transport.addTransportListener(transportListener);
}
项目:streamline    文件:EmailNotifier.java   
/**
 * Return a {@link Transport} object from the session registering the passed in transport listener
 * for delivery notifications.
 */
private Transport getEmailTransport(Session session, TransportListener listener) {
    try {
        Transport transport = session.getTransport();
        transport.addTransportListener(listener);
        if (!transport.isConnected()) {
            transport.connect();
        }
        LOG.debug("Email transport {}, transport listener {}", transport, listener);
        return transport;
    } catch (MessagingException ex) {
        LOG.error("Got exception while initializing transport", ex);
        throw new NotifierRuntimeException("Got exception while initializing transport", ex);
    }
}
项目:javamail    文件:TransportTest.java   
@Test
public void transportNOPTest() throws Exception {
    TransportListener transportListener = Mockito.mock(TransportListener.class);
    Message message = generateMessage();
    Transport transport = session.getTransport("nop");
    transport.addTransportListener(transportListener);
    transport.sendMessage(message, toAddress);
    waitForListeners();
    ArgumentCaptor<TransportEvent> transportEventArgumentCaptor = ArgumentCaptor.forClass(TransportEvent.class);
    verify(transportListener).messageDelivered(transportEventArgumentCaptor.capture());
    TransportEvent event = transportEventArgumentCaptor.getValue();
    assertEquals(message, event.getMessage());
    assertEquals(TransportEvent.MESSAGE_DELIVERED, event.getType());
    assertArrayEquals(toAddress, event.getValidSentAddresses());
}
项目:smtp-connection-pool    文件:SmtpConnectionFactoryBuilder.java   
public SmtpConnectionFactoryBuilder defaultTransportListeners(TransportListener... listeners) {
  defaultTransportListeners = Arrays.asList(requireNonNull(listeners));
  return this;
}
项目:smtp-connection-pool    文件:SmtpConnectionFactory.java   
public SmtpConnectionFactory(Session session, TransportStrategy transportStrategy, ConnectionStrategy connectionStrategy, Collection<TransportListener> defaultTransportListeners) {
  this.session = session;
  this.transportFactory = transportStrategy;
  this.connectionStrategy = connectionStrategy;
  this.defaultTransportListeners = new ArrayList<>(defaultTransportListeners);
}
项目:smtp-connection-pool    文件:SmtpConnectionFactory.java   
public SmtpConnectionFactory(Session session, TransportStrategy transportFactory, ConnectionStrategy connectionStrategy) {
  this(session, transportFactory, connectionStrategy, Collections.<TransportListener>emptyList());
}
项目:smtp-connection-pool    文件:SmtpConnectionFactory.java   
public void setDefaultListeners(Collection<TransportListener> listeners) {
  defaultTransportListeners = new CopyOnWriteArrayList<>(Objects.requireNonNull(listeners));
}
项目:smtp-connection-pool    文件:SmtpConnectionFactory.java   
public List<TransportListener> getDefaultListeners() {
  return new ArrayList<>(defaultTransportListeners);
}
项目:smtp-connection-pool    文件:SmtpConnectionFactory.java   
private void initDefaultListeners(ClosableSmtpConnection smtpTransport) {
  for (TransportListener transportListener : defaultTransportListeners) {
    smtpTransport.addTransportListener(transportListener);
  }
}
项目:smtp-connection-pool    文件:DefaultClosableSmtpConnection.java   
public void addTransportListener(TransportListener l) {
  transportListeners.add(l);
  delegate.addTransportListener(l);
}
项目:smtp-connection-pool    文件:DefaultClosableSmtpConnection.java   
public void removeTransportListener(TransportListener l) {
  transportListeners.remove(l);
  delegate.removeTransportListener(l);
}
项目:smtp-connection-pool    文件:DefaultClosableSmtpConnection.java   
public void clearListeners() {
  for (TransportListener transportListener : transportListeners) {
    delegate.removeTransportListener(transportListener);
  }
  transportListeners.clear();
}
项目:smtp-connection-pool    文件:ClosableSmtpConnection.java   
/**
 * Add a new {@link TransportListener}
 *
 * @param l
 */
void addTransportListener(TransportListener l);
项目:smtp-connection-pool    文件:ClosableSmtpConnection.java   
/**
 * Remove the provided {@link TransportListener}
 *
 * @param l
 */
void removeTransportListener(TransportListener l);