Repository: karaf Updated Branches: refs/heads/master 2018ec2d9 -> 813d5bfa5
[KARAF-3625] Give some time to find encryption service in order to avoid race condition throwing IllegalStateException Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/813d5bfa Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/813d5bfa Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/813d5bfa Branch: refs/heads/master Commit: 813d5bfa57c575d3279d3d88121786ecb14eb9aa Parents: 2018ec2 Author: Jean-Baptiste Onofré <[email protected]> Authored: Tue Apr 7 18:13:07 2015 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Tue Apr 7 19:40:41 2015 +0200 ---------------------------------------------------------------------- .../jaas/modules/encryption/EncryptionSupport.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/813d5bfa/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java ---------------------------------------------------------------------- diff --git a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java index ebdaa77..18e695d 100644 --- a/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java +++ b/jaas/modules/src/main/java/org/apache/karaf/jaas/modules/encryption/EncryptionSupport.java @@ -78,6 +78,20 @@ public class EncryptionSupport { encryptionServiceReferences = bundleContext.getServiceReferences( EncryptionService.class.getName(), name != null && name.length() > 0 ? "(name=" + name + ")" : null); + int timeout = 0; + while (encryptionServiceReferences == null || encryptionServiceReferences.length == 0) { + try { + Thread.sleep(500); + } catch (InterruptedException ie) { + // nothing to do + } + encryptionServiceReferences = bundleContext.getServiceReferences( + EncryptionService.class.getName(), + name != null && name.length() > 0 ? "(name=" + name + ")" : null); + timeout++; + if (timeout == 40) + break; + } } catch (InvalidSyntaxException e) { throw new IllegalStateException("The encryption service filter is not well formed.", e); } @@ -85,7 +99,7 @@ public class EncryptionSupport { if (name != null && name.length() > 0) { throw new IllegalStateException("Encryption service " + name + " not found. Please check that the encryption service is correctly set up."); } else { - throw new IllegalStateException("No encryption service found. Please install the Karaf encryption feature and check that the encryption algorithm is supported.."); + throw new IllegalStateException("No encryption service found. Please install the Karaf encryption feature and check that the encryption algorithm is supported."); } } Arrays.sort(encryptionServiceReferences);
