- Notifications
You must be signed in to change notification settings - Fork50
yahoo/imapnio
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Java library that supports NIO (Non-blocking I/O) based IMAP clients.
The IMAP NIO client provides a framework to access an IMAP message store using None-blocking I/O mechanism. This design scales well for thousands of connections per machine and reduces contention when using a large number of threads and CPUs.
The traditional accessing IMAP message store usesJavaMail API, which requires a blocking I/O. In this case, threads are blocked when performing I/O with the other end. This project was developed to relieve the waiting thread to perform other tasks, and it's design efficiently improves thread utilization to maximize hardware throughput and capacity.
Some of the more distinguishing features of this library are:
- Highly customizable thread model and server/client idle max limit.
- Leverages the well-established frameworkNetty
- Future-based design enables a clean separation of IMAP client threads pool versus consumers threads pool.
- IMAPv4,RFC3501 support.
- ID command,RFC2971 support.
- IDLE command,RFC2177 support
- MOVE command,RFC6851 support
- UNSELECT command,RFC3691 support
This project is ideal for applications that have a high requirement to optimize thread utilization and improve overall resource capacity. Specifically, this is best for situations where users perform a very high level of sessions and communication with the IMAP server.
This is a Java library. After downloading it, compile it usingmvn clean install
Then, update your project's pom.xml file dependencies, as follows:
<dependency> <groupId>com.yahoo.imapnio</groupId> <artifactId>imapnio.core</artifactId> <version>5.0.15</version> </dependency>
Finally, import the relevant classes and use this library according to the usage section below.
- For contributors run deploy to do a push to nexus servers
$ mvn clean deploy -Dgpg.passphrase=[pathPhrase]
The following code examples demonstrate basic functionality relate to connecting to and communicating with IMAP servers.
// Create a ImapAsyncClient instance with number of threads to handle the server requestsfinalintnumOfThreads =5;finalImapAsyncClientimapClient =newImapAsyncClient(numOfThreads);
// Create a new session via the ImapAsyncClient instance created above and connect to that server. For the illustration purpose,// "imaps://imap.server.com:993" is usedfinalURIserverUri =newURI("imaps://imap.server.com:993");finalImapAsyncSessionConfigconfig =newImapAsyncSessionConfig();config.setConnectionTimeoutMillis(5000);config.setReadTimeoutMillis(6000);finalList<String>sniNames =null;finalInetSocketAddresslocalAddress =null;finalFuture<ImapAsyncCreateSessionResponse>future =imapClient.createSession(serverUri,config,localAddress,sniNames,DebugMode.DEBUG_OFF);//this version is a future-based nio client. Check whether future is done by following code.if (future.isDone()) {System.out.println("Future is done."); }
Following codes uses a Capability command as an example.
// Executes the capability commandfinalFuture<ImapAsyncResponse>capaCmdFuture =session.execute(newCapaCommand());
If the future of the executed command is done, obtain the response.Following example shows how to read ImapAsyncResponse which wraps the content sent from the server.
if (capaCmdFuture.isDone()) {System.out.println("Capability command is done.");finalImapAsyncResponseresp =capaCmdFuture.get(5,TimeUnit.MILLISECONDS);finalImapResponseMappermapper =newImapResponseMapper();finalCapabilitycapa =mapper.readValue(resp.getResponseLines().toArray(newIMAPResponse[0]),Capability.class);finalList<String>values =capa.getCapability("AUTH"); }
This release, 2.0.x, is a major release. Changes are:
- It supports non-blocking IO functionality through providing callers with java.util.concurrent.Future object.
- Listener-based non-blocking IO capability will not be supported in this release.
This release, 5.0.x, is a major release. Changes are:
- It supports request and response bytes counting per command
Please refer to thecontributing.md for information about how to get involved. We welcome issues, questions, and pull requests. Pull Requests are welcome.
Fan Su :fsu@yahooinc.comVikram Nagulakonda :nvikram@yahooinc.com
This project is licensed under the terms of theApache 2.0 open source license. Please refer toLICENSE for the full terms.
About
Java imap nio client that is designed to scale well for thousands of connections per machine and reduce contention when using large number of threads and cpus.