Skip to content

Commit

Permalink
Adding ApnsService.testConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
notnoop committed Jan 13, 2010
1 parent 32d9d37 commit a4a48c3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/notnoop/apns/ApnsService.java
Expand Up @@ -153,4 +153,13 @@ public interface ApnsService {
* while retrieving invalid device connection
*/
Map<String, Date> getInactiveDevices() throws NetworkIOException;

/**
* Test that the service is setup properly and the Apple servers
* are reachable.
*
* @throws NetworkIOException if the Apple servers aren't reachable
* or the service cannot send notifications for now
*/
void testConnection() throws NetworkIOException;
}
Expand Up @@ -72,5 +72,4 @@ public void push(Collection<byte[]> deviceTokens, byte[] payload) throws Network
public Map<String, Date> getInactiveDevices() throws NetworkIOException {
return feedback.getInactiveDevices();
}

}
Expand Up @@ -37,5 +37,6 @@

public interface ApnsConnection extends Closeable {
void sendMessage(ApnsNotification m) throws NetworkIOException;
void testConnection() throws NetworkIOException;
ApnsConnection copy();
}
Expand Up @@ -133,4 +133,10 @@ public synchronized void sendMessage(ApnsNotification m) throws NetworkIOExcepti
public ApnsConnectionImpl copy() {
return new ApnsConnectionImpl(factory, host, port, reconnectPolicy, delegate);
}

public void testConnection() throws NetworkIOException {
ApnsConnectionImpl testConnection = new ApnsConnectionImpl(factory, host, port, reconnectPolicy, ApnsDelegate.EMPTY);
testConnection.sendMessage(new ApnsNotification(new byte[] {0}, new byte[]{0}));
testConnection.close();
}
}
Expand Up @@ -61,4 +61,8 @@ public void close() {
}
Utilities.close(prototype);
}

public void testConnection() {
prototype.testConnection();
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/notnoop/apns/internal/ApnsServiceImpl.java
Expand Up @@ -52,4 +52,8 @@ public void start() {
public void stop() {
Utilities.close(connection);
}

public void testConnection() {
connection.testConnection();
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/notnoop/apns/internal/MinaAdaptor.java
Expand Up @@ -11,6 +11,7 @@
import org.apache.mina.transport.socket.nio.NioSocketConnector;

import com.notnoop.apns.ApnsNotification;
import com.notnoop.exceptions.NetworkIOException;

public class MinaAdaptor extends AbstractApnsService {
NioSocketConnector connector;
Expand Down Expand Up @@ -58,4 +59,8 @@ public void stop() {
cf.getSession().close(false).awaitUninterruptibly(100000);
connector.dispose();
}

public void testConnection() throws NetworkIOException {
// TODO: Implement me in a bit
}
}
Expand Up @@ -94,4 +94,8 @@ public Map<String, Date> getInactiveDevices() throws NetworkIOException {
return service.getInactiveDevices();
}

public void testConnection() throws NetworkIOException {
service.testConnection();
}

}
Expand Up @@ -10,6 +10,7 @@

import com.notnoop.apns.ApnsNotification;
import com.notnoop.apns.ApnsService;
import com.notnoop.exceptions.NetworkIOException;

public class QueuedApnsServiceTest {

Expand Down Expand Up @@ -96,6 +97,6 @@ public ApnsConnection copy() {
}

public void close() throws IOException {}

public void testConnection() throws NetworkIOException {}
}
}

1 comment on commit a4a48c3

@gymoese
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, nearly exactly as I implemented it myself - I will revert my own changes - thanks!

Please sign in to comment.