@Override
 SignatureVerifier construct(final DataStore<Long, User> dataStore) {
   try {
     identityDatastore =
         DataStoreFactory.getDataStore(ByteBuffer.class, HashIdentity.class, new Configuration());
   } catch (GoraException e) {
     fail("Unable to initialize identity datastore");
   }
   return new SignatureVerifierMock(dataStore, identityDatastore);
 }
Exemple #2
0
 public static MockDataStore get() {
   MockDataStore dataStore;
   try {
     dataStore =
         DataStoreFactory.getDataStore(
             MockDataStore.class, String.class, MockPersistent.class, new Configuration());
     return dataStore;
   } catch (GoraException ex) {
     throw new RuntimeException(ex);
   }
 }
 Base() throws GoraException {
   userDatastore = DataStoreFactory.getDataStore(Long.class, User.class, new Configuration());
   notifier = new Notifier();
   pendingNotificationDataStore =
       DataStoreFactory.getDataStore(Long.class, PendingNotification.class, new Configuration());
   clientNotifier = new ClientNotifier(notifier, pendingNotificationDataStore);
   identityDataStore =
       DataStoreFactory.getDataStore(ByteBuffer.class, HashIdentity.class, new Configuration());
   sendContactCard = new SendContactCard(userDatastore, identityDataStore, clientNotifier);
   final User user = new User();
   final ByteBuffer b = ByteBuffer.wrap("".getBytes());
   b.mark();
   user.setBlind(b);
   user.setId(clientId.getUser());
   user.setIdentities(new ArrayList<>());
   user.setSentRequests(new ArrayList<>());
   final Map<CharSequence, Client> clients = new HashMap<>(1);
   clients.put(
       TypeConverter.convert(clientId.getClient()), createClient(clientId, verificationKey));
   user.setClients(clients);
   userDatastore.put(user.getId(), user);
 }
  private void readFlushed(Configuration conf) throws Exception {
    DataStore<Utf8, Flushed> flushedTable =
        DataStoreFactory.getDataStore(Utf8.class, Flushed.class, conf);

    Query<Utf8, Flushed> query = flushedTable.newQuery();
    Result<Utf8, Flushed> result = flushedTable.execute(query);

    ArrayList<String> flushedEntries = new ArrayList<String>();
    while (result.next()) {
      flushedEntries.add(result.getKey() + ":" + result.get().getCount());
    }

    conf.setStrings("goraci.verify.flushed", flushedEntries.toArray(new String[] {}));

    flushedTable.close();
  }
Exemple #5
0
 @Override
 public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) {
   super.initialize(keyClass, persistentClass, properties);
   CachingProvider cachingProvider =
       Caching.getCachingProvider(properties.getProperty(GORA_DEFAULT_JCACHE_PROVIDER_KEY));
   if (properties.getProperty(JCACHE_CACHE_NAMESPACE_PROPERTY_KEY) != null) {
     goraCacheNamespace = properties.getProperty(JCACHE_CACHE_NAMESPACE_PROPERTY_KEY);
   }
   try {
     this.persistentDataStore =
         DataStoreFactory.getDataStore(keyClass, persistentClass, new Configuration());
   } catch (GoraException ex) {
     LOG.error("Couldn't initialize persistent DataStore.", ex);
   }
   if (properties
       .getProperty(GORA_DEFAULT_JCACHE_PROVIDER_KEY)
       .contains(HAZELCAST_SERVER_CACHE_PROVIDER_IDENTIFIER)) {
     Config config =
         new ClasspathXmlConfig(properties.getProperty(GORA_DEFAULT_JCACHE_HAZELCAST_CONFIG_KEY));
     hazelcastInstance = Hazelcast.newHazelcastInstance(config);
   } else {
     try {
       ClientConfig config =
           new XmlClientConfigBuilder(
                   properties.getProperty(GORA_DEFAULT_JCACHE_HAZELCAST_CONFIG_KEY))
               .build();
       hazelcastInstance = HazelcastClient.newHazelcastClient(config);
     } catch (IOException ex) {
       LOG.error("Couldn't locate the client side cache provider configuration.", ex);
     }
   }
   Properties providerProperties = new Properties();
   providerProperties.setProperty(
       HazelcastCachingProvider.HAZELCAST_INSTANCE_NAME, hazelcastInstance.getName());
   try {
     manager =
         cachingProvider.getCacheManager(new URI(goraCacheNamespace), null, providerProperties);
   } catch (URISyntaxException ex) {
     LOG.error("Couldn't initialize cache manager to bounded hazelcast instance.", ex);
     manager = cachingProvider.getCacheManager();
   }
   if (((properties.getProperty(JCACHE_AUTO_CREATE_CACHE_PROPERTY_KEY) != null)
           && Boolean.valueOf(properties.getProperty(JCACHE_AUTO_CREATE_CACHE_PROPERTY_KEY)))
       || ((manager.getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass)
           == null))) {
     cacheEntryList = new ConcurrentSkipListSet<>();
     cacheConfig = new CacheConfig<K, T>();
     cacheConfig.setTypes(keyClass, persistentClass);
     if (properties.getProperty(JCACHE_READ_THROUGH_PROPERTY_KEY) != null) {
       cacheConfig.setReadThrough(
           Boolean.valueOf(properties.getProperty(JCACHE_READ_THROUGH_PROPERTY_KEY)));
     } else {
       cacheConfig.setReadThrough(true);
     }
     if (properties.getProperty(JCACHE_WRITE_THROUGH_PROPERTY_KEY) != null) {
       cacheConfig.setWriteThrough(
           Boolean.valueOf(properties.getProperty(JCACHE_WRITE_THROUGH_PROPERTY_KEY)));
     } else {
       cacheConfig.setWriteThrough(true);
     }
     if (properties.getProperty(JCACHE_STORE_BY_VALUE_PROPERTY_KEY) != null) {
       cacheConfig.setStoreByValue(
           Boolean.valueOf(properties.getProperty(JCACHE_STORE_BY_VALUE_PROPERTY_KEY)));
     }
     if (properties.getProperty(JCACHE_STATISTICS_PROPERTY_KEY) != null) {
       cacheConfig.setStatisticsEnabled(
           Boolean.valueOf(properties.getProperty(JCACHE_STATISTICS_PROPERTY_KEY)));
     }
     if (properties.getProperty(JCACHE_MANAGEMENT_PROPERTY_KEY) != null) {
       cacheConfig.setStatisticsEnabled(
           Boolean.valueOf(properties.getProperty(JCACHE_MANAGEMENT_PROPERTY_KEY)));
     }
     if (properties.getProperty(JCACHE_EVICTION_POLICY_PROPERTY_KEY) != null) {
       cacheConfig
           .getEvictionConfig()
           .setEvictionPolicy(
               EvictionPolicy.valueOf(
                   properties.getProperty(JCACHE_EVICTION_POLICY_PROPERTY_KEY)));
     }
     if (properties.getProperty(JCACHE_EVICTION_MAX_SIZE_POLICY_PROPERTY_KEY) != null) {
       cacheConfig
           .getEvictionConfig()
           .setMaximumSizePolicy(
               EvictionConfig.MaxSizePolicy.valueOf(
                   properties.getProperty(JCACHE_EVICTION_MAX_SIZE_POLICY_PROPERTY_KEY)));
     }
     if (properties.getProperty(JCACHE_EVICTION_SIZE_PROPERTY_KEY) != null) {
       cacheConfig
           .getEvictionConfig()
           .setSize(Integer.valueOf(properties.getProperty(JCACHE_EVICTION_SIZE_PROPERTY_KEY)));
     }
     if (properties.getProperty(JCACHE_EXPIRE_POLICY_PROPERTY_KEY) != null) {
       String expiryPolicyIdentifier = properties.getProperty(JCACHE_EXPIRE_POLICY_PROPERTY_KEY);
       if (expiryPolicyIdentifier.equals(JCACHE_ACCESSED_EXPIRY_IDENTIFIER)) {
         cacheConfig.setExpiryPolicyFactory(
             FactoryBuilder.factoryOf(
                 new AccessedExpiryPolicy(
                     new Duration(
                         TimeUnit.SECONDS,
                         Integer.valueOf(
                             properties.getProperty(
                                 JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
       } else if (expiryPolicyIdentifier.equals(JCACHE_CREATED_EXPIRY_IDENTIFIER)) {
         cacheConfig.setExpiryPolicyFactory(
             FactoryBuilder.factoryOf(
                 new CreatedExpiryPolicy(
                     new Duration(
                         TimeUnit.SECONDS,
                         Integer.valueOf(
                             properties.getProperty(
                                 JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
       } else if (expiryPolicyIdentifier.equals(JCACHE_MODIFIED_EXPIRY_IDENTIFIER)) {
         cacheConfig.setExpiryPolicyFactory(
             FactoryBuilder.factoryOf(
                 new ModifiedExpiryPolicy(
                     new Duration(
                         TimeUnit.SECONDS,
                         Integer.valueOf(
                             properties.getProperty(
                                 JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
       } else if (expiryPolicyIdentifier.equals(JCACHE_TOUCHED_EXPIRY_IDENTIFIER)) {
         cacheConfig.setExpiryPolicyFactory(
             FactoryBuilder.factoryOf(
                 new TouchedExpiryPolicy(
                     new Duration(
                         TimeUnit.SECONDS,
                         Integer.valueOf(
                             properties.getProperty(
                                 JCACHE_EXPIRE_POLICY_DURATION_PROPERTY_KEY))))));
       }
     }
     if (properties.getProperty(HAZELCAST_CACHE_IN_MEMORY_FORMAT_PROPERTY_KEY) != null) {
       String inMemoryFormat =
           properties.getProperty(HAZELCAST_CACHE_IN_MEMORY_FORMAT_PROPERTY_KEY);
       if (inMemoryFormat.equals(HAZELCAST_CACHE_BINARY_IN_MEMORY_FORMAT_IDENTIFIER)
           || inMemoryFormat.equals(HAZELCAST_CACHE_OBJECT_IN_MEMORY_FORMAT_IDENTIFIER)
           || inMemoryFormat.equals(HAZELCAST_CACHE_NATIVE_IN_MEMORY_FORMAT_IDENTIFIER)) {
         cacheConfig.setInMemoryFormat(InMemoryFormat.valueOf(inMemoryFormat));
       }
     }
     cacheConfig.setCacheLoaderFactory(
         JCacheCacheFactoryBuilder.factoryOfCacheLoader(
             this.persistentDataStore, keyClass, persistentClass));
     cacheConfig.setCacheWriterFactory(
         JCacheCacheFactoryBuilder.factoryOfCacheWriter(
             this.persistentDataStore, keyClass, persistentClass));
     cache =
         manager.createCache(persistentClass.getSimpleName(), cacheConfig).unwrap(ICache.class);
   } else {
     cache =
         manager
             .getCache(super.getPersistentClass().getSimpleName(), keyClass, persistentClass)
             .unwrap(ICache.class);
     this.populateLocalCacheEntrySet(cache);
   }
   cache.registerCacheEntryListener(
       new MutableCacheEntryListenerConfiguration<>(
           JCacheCacheFactoryBuilder.factoryOfEntryListener(
               new JCacheCacheEntryListener<K, T>(cacheEntryList)),
           null,
           true,
           true));
   LOG.info("JCache Gora datastore initialized successfully.");
 }