notnoop / java-apns

Java Apple Push Notification Service Provider
notnoop.github.com/java-apns
BSD 3-Clause "New" or "Revised" License
1.79k stars 657 forks source link

Add option to build without start #90

Closed andrewchen5678 closed 10 years ago

andrewchen5678 commented 11 years ago

There should be a way to build without actually starting the service, for the ApnsServiceBuilder.java, there should be a method which does build() without calling service.start() because sometimes we want to build the ApnsService without starting it right away.

public ApnsService build() {
    checkInitialization();
    ApnsService service;

    SSLSocketFactory sslFactory = sslContext.getSocketFactory();
    ApnsFeedbackConnection feedback = new ApnsFeedbackConnection(sslFactory, feedbackHost, feedbackPort, proxy);

    ApnsConnection conn = new ApnsConnectionImpl(sslFactory, gatewayHost, 
            gatewaPort, proxy, reconnectPolicy, 
            delegate, errorDetection, cacheLength, autoAdjustCacheLength);
    if (pooledMax != 1) {
        conn = new ApnsPooledConnection(conn, pooledMax, executor);
    }

    service = new ApnsServiceImpl(conn, feedback);

    if (isQueued) {
        service = new QueuedApnsService(service);
    }

    if (isBatched) {
        service = new BatchApnsService(conn, feedback, batchWaitTimeInSec, batchMaxWaitTimeInSec, batchThreadFactory);
    }

    service.start();

    return service;
}
froh42 commented 11 years ago

Hi @andrewchen5678 ,

please elaborate a bit on why you'd need that. I'm trying to understand how people use java-apns.

andrewchen5678 commented 11 years ago

Sometime when I build a QueuedApnsService or some other ApnsService, I don't want to start them right away because I want to do some customization to it first.

froh42 commented 10 years ago

@andrewchen5678, if you're still interested in that feature feel free to supply a patch.

Currently I can on focus on getting the current feature set stable for a 1.0.0.