SLING-8751 - Use different connect timeout, check for null at adaptTo
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/queue/impl/LimitPoller.java b/src/main/java/org/apache/sling/distribution/journal/impl/queue/impl/LimitPoller.java
index d7a1002..d21edf1 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/queue/impl/LimitPoller.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/queue/impl/LimitPoller.java
@@ -43,6 +43,9 @@
 
 @ParametersAreNonnullByDefault
 public class LimitPoller {
+    // Longer timeout for first message as it includes connecting to the journal
+    private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(30);
+
     private final Logger log = LoggerFactory.getLogger(LimitPoller.class);
     
     private final long minOffset;
@@ -68,7 +71,7 @@
 
     public List<FullMessage<PackageMessage>> fetch(Duration timeOut) {
         try {
-            boolean timeout = false;
+            boolean timeout = nextMessage.tryAcquire(CONNECT_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
             while (!timeout && this.messages.size() < maxMessages) {
                 timeout = !nextMessage.tryAcquire(timeOut.toMillis(), TimeUnit.MILLISECONDS);
             }
diff --git a/src/main/java/org/apache/sling/distribution/journal/impl/shared/PackageBrowser.java b/src/main/java/org/apache/sling/distribution/journal/impl/shared/PackageBrowser.java
index 56ef007..713537d 100644
--- a/src/main/java/org/apache/sling/distribution/journal/impl/shared/PackageBrowser.java
+++ b/src/main/java/org/apache/sling/distribution/journal/impl/shared/PackageBrowser.java
@@ -84,7 +84,11 @@
         } else {
             String pkgBinRef = pkgMsg.getPkgBinaryRef();
             try {
-                ValueFactory factory = resolver.adaptTo(Session.class).getValueFactory();
+                Session session = resolver.adaptTo(Session.class);
+                if (session == null) {
+                    throw new DistributionException("Unable to get Oak session");
+                }
+                ValueFactory factory = session.getValueFactory();
                 Binary binary = factory.createValue(new SimpleReferenceBinary(pkgBinRef)).getBinary();
                 return binary.getStream();
             } catch (RepositoryException e) {