Package org.infinispan.util

Examples of org.infinispan.util.TypedProperties


    }


    private void buildCacheStore(OperationContext context, LoaderConfigurationBuilder builder, String containerName, ModelNode store, String storeKey, List<Dependency<?>> dependencies)
            throws OperationFailedException {
        final Properties properties = new TypedProperties();
        if (store.hasDefined(ModelKeys.PROPERTY)) {
            for (Property property : store.get(ModelKeys.PROPERTY).asPropertyList()) {
                // the format of the property elements
                //  "property" => {
                //       "relative-to" => {"value" => "fred"},
                //   }
                String propertyName = property.getName();
                Property complexValue = property.getValue().asProperty();
                String propertyValue = complexValue.getValue().asString();
                properties.setProperty(propertyName, propertyValue);
            }
        }
        builder.withProperties(properties);

        ModelNode resolvedValue = null ;
        if (storeKey.equals(ModelKeys.FILE_STORE)) {
            builder.cacheLoader(new FileCacheStore());

            final String path = ((resolvedValue = CommonAttributes.PATH.resolveModelAttribute(context, store)).isDefined()) ? resolvedValue.asString() : containerName ;

            Injector<String> injector = new SimpleInjector<String>() {
                @Override
                public void inject(String value) {
                    StringBuilder location = new StringBuilder(value);
                    if (path != null) {
                        location.append(File.separatorChar).append(path);
                    }
                    properties.setProperty("location", location.toString());
                }
            };
            final String relativeTo = ((resolvedValue = CommonAttributes.RELATIVE_TO.resolveModelAttribute(context, store)).isDefined()) ? resolvedValue.asString() : ServerEnvironment.SERVER_DATA_DIR ;
            dependencies.add(new Dependency<String>(AbstractPathService.pathNameOf(relativeTo), String.class, injector));
            properties.setProperty("fsyncMode", "perWrite");
        } else if (storeKey.equals(ModelKeys.STRING_KEYED_JDBC_STORE) || storeKey.equals(ModelKeys.BINARY_KEYED_JDBC_STORE) || storeKey.equals(ModelKeys.MIXED_KEYED_JDBC_STORE)) {
            builder.cacheLoader(this.createJDBCStore(properties, context, store));

            final String datasource = CommonAttributes.DATA_SOURCE.resolveModelAttribute(context, store).asString() ;

            dependencies.add(new Dependency<Object>(ServiceName.JBOSS.append("data-source", datasource)));
            properties.setProperty("datasourceJndiLocation", datasource);
            properties.setProperty("connectionFactoryClass", ManagedConnectionFactory.class.getName());
        } else if (storeKey.equals(ModelKeys.REMOTE_STORE)) {
            builder.cacheLoader(new RemoteCacheStore());
            for (ModelNode server: store.require(ModelKeys.REMOTE_SERVERS).asList()) {
                String outboundSocketBinding = server.get(ModelKeys.OUTBOUND_SOCKET_BINDING).asString();
                Injector<OutboundSocketBinding> injector = new SimpleInjector<OutboundSocketBinding>() {
                    @Override
                    public void inject(OutboundSocketBinding value) {
                        try {
                            String address = value.getDestinationAddress().getHostAddress() + ":" + value.getDestinationPort();
                            String serverList = properties.getProperty("serverList");
                            properties.setProperty("serverList", (serverList == null) ? address : serverList + ";" + address);
                        } catch (UnknownHostException e) {
                            throw InfinispanMessages.MESSAGES.failedToInjectSocketBinding(e, value);
                        }
                    }
                };
                dependencies.add(new Dependency<OutboundSocketBinding>(OutboundSocketBinding.OUTBOUND_SOCKET_BINDING_BASE_SERVICE_NAME.append(outboundSocketBinding), OutboundSocketBinding.class, injector));
            }
            if (store.hasDefined(ModelKeys.CACHE)) {
                properties.setProperty("remoteCacheName", store.get(ModelKeys.CACHE).asString());
                properties.setProperty("useDefaultRemoteCache", Boolean.toString(false));
            } else {
                properties.setProperty("useDefaultRemoteCache", Boolean.toString(true));
            }
            if (store.hasDefined(ModelKeys.SOCKET_TIMEOUT)) {
                properties.setProperty("soTimeout", store.require(ModelKeys.SOCKET_TIMEOUT).asString());
            }
            if (store.hasDefined(ModelKeys.TCP_NO_DELAY)) {
                properties.setProperty("tcpNoDelay", store.require(ModelKeys.TCP_NO_DELAY).asString());
            }
        } else {
            String className = store.require(ModelKeys.CLASS).asString();
            try {
                CacheLoader loader = CacheLoader.class.getClassLoader().loadClass(className).asSubclass(CacheLoader.class).newInstance();
View Full Code Here


      return pxml;
   }

   @Override
   public TypedProperties unmarshal(PropertiesType props) throws Exception {
      TypedProperties tp = new TypedProperties();
      for (Property p : props.properties) {
         tp.put(p.name, p.value);
      }
      return tp;
   }
View Full Code Here

   protected TypedProperties toTypedProperties(Properties p) {
      return TypedProperties.toTypedProperties(p);
   }

   protected TypedProperties toTypedProperties(String s) {
      TypedProperties tp = new TypedProperties();
      if (s != null && s.trim().length() > 0) {
         InputStream stream = new ByteArrayInputStream(s.getBytes());
         try {
            tp.load(stream);
         } catch (IOException e) {
            throw new ConfigurationException("Unable to parse properties string " + s, e);
         }
      }
      return tp;
View Full Code Here

      testImmutability("properties");
      // JBCACHE-531: escape all backslash characters
      // replace any "\" that is not preceded by a backslash with "\\"
      properties = XmlConfigHelper.escapeBackslashes(properties);
      ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
      this.properties = new TypedProperties();
      this.properties.load(is);
      is.close();
   }
View Full Code Here

            throw new ConfigurationException("Couldn't find a setter named [" + setter + "] which takes a single parameter, for parameter " + propName + " on class [" + objectClass + "]");
      }
   }

   public static Properties extractProperties(Element source) {
      TypedProperties p = new TypedProperties();
      NodeList list = source.getElementsByTagName("property");
      if (list == null) return null;
      // loop through attributes
      for (int loop = 0; loop < list.getLength(); loop++) {
         Node node = list.item(loop);
         if (node.getNodeType() != Node.ELEMENT_NODE) continue;

         // for each element (attribute) ...
         Element element = (Element) node;
         String name = element.getAttribute("name");
         String valueStr = element.getAttribute("value");

         if (valueStr.length() > 0) {
            valueStr = valueStr.trim();
            valueStr = StringPropertyReplacer.replaceProperties(valueStr);
            p.put(name, valueStr);
         }
      }
      return p.isEmpty() ? null : p;
   }
View Full Code Here

*/
public class DefaultExecutorFactory implements ExecutorFactory {
   private final static AtomicInteger counter = new AtomicInteger(0);

   public ExecutorService getExecutor(Properties p) {
      TypedProperties tp = TypedProperties.toTypedProperties(p);
      int maxThreads = tp.getIntProperty("maxThreads", 1);
      int queueSize = tp.getIntProperty("queueSize", 100000);
      final String threadNamePrefix = tp.getProperty("threadNamePrefix", "Thread");

      ThreadFactory tf = new ThreadFactory() {
         public Thread newThread(Runnable r) {
            Thread th = new Thread(r, threadNamePrefix + "-" + counter.getAndIncrement());
            th.setDaemon(true);
View Full Code Here

      return this;
   }

   @Override
   public HotRodServerConfigurationBuilder withProperties(Properties properties) {
      TypedProperties typed = TypedProperties.toTypedProperties(properties);
      super.withProperties(typed);

      if (typed != null) {
         if (typed.containsKey(Main.PROP_KEY_PROXY_HOST())) {
            this.proxyHost(typed.getProperty(Main.PROP_KEY_PROXY_HOST(), proxyHost, true));
         }
         this.proxyPort(typed.getIntProperty(Main.PROP_KEY_PROXY_PORT(), proxyPort, true));
         this.topologyLockTimeout(typed.getLongProperty(Main.PROP_KEY_TOPOLOGY_LOCK_TIMEOUT(), topologyLockTimeout, true));
         this.topologyReplTimeout(typed.getLongProperty(Main.PROP_KEY_TOPOLOGY_LOCK_TIMEOUT(), topologyReplTimeout, true));
         this.topologyStateTransfer(typed.getBooleanProperty(Main.PROP_KEY_TOPOLOGY_STATE_TRANSFER(), topologyStateTransfer, true));
         this.topologyUpdateTimeout(typed.getLongProperty(Main.PROP_KEY_TOPOLOGY_UPDATE_TIMEOUT(), topologyUpdateTimeout, true));
      }

      return this;
   }
View Full Code Here

      Properties p = getProperties();
      try {
         p.setProperty(key, value);
      } catch (UnsupportedOperationException e) {
         // Most likely immutable, so let's work around that
         TypedProperties writableProperties = new TypedProperties(p);
         writableProperties.setProperty(key, value);
         setProperties(writableProperties);
      }
   }
View Full Code Here

      // RemoteCacheStoreConfiguration
      config.setRawValues(rawValues);
      config.setRemoteCacheName(remoteCacheName);
      config.setAsyncExecutorFactory(asyncExecutorFactory.factory());

      TypedProperties p = new TypedProperties();

      // Async Executor
      p.putAll(asyncExecutorFactory.properties());

      // Connection Pool
      p.put("maxActive", Integer.toString(connectionPool.maxActive()));
      p.put("maxIdle", Integer.toString(connectionPool.maxIdle()));
      p.put("maxTotal", Integer.toString(connectionPool.maxTotal()));
      p.put("minIdle", connectionPool.minIdle());
      p.put("minEvictableIdleTimeMillis", Long.toString(connectionPool.minEvictableIdleTime()));
      p.put("testWhileIdle", Boolean.toString(connectionPool.testWhileIdle()));
      p.put("timeBetweenEvictionRunsMillis", Long.toString(connectionPool.timeBetweenEvictionRuns()));
      p.put("whenExhaustedAction", Integer.toString(connectionPool.exhaustedAction().ordinal()));

      config.setTypedProperties(p);

      Properties hrp = new Properties();
      hrp.put(ConfigurationProperties.CONNECT_TIMEOUT, Long.toString(connectionTimeout));
View Full Code Here

public class DefaultExecutorFactory implements ExecutorFactory {
   private final AtomicInteger counter = new AtomicInteger(0);

   @Override
   public ExecutorService getExecutor(Properties p) {
      TypedProperties tp = TypedProperties.toTypedProperties(p);
      int maxThreads = tp.getIntProperty("maxThreads", 1);
      int queueSize = tp.getIntProperty("queueSize", 100000);
      int coreThreads = queueSize == 0 ? 1 : tp.getIntProperty("coreThreads", maxThreads);
      long keepAliveTime = tp.getLongProperty("keepAliveTime", 60000);
      final int threadPrio = tp.getIntProperty("threadPriority", Thread.MIN_PRIORITY);
      final String threadNamePrefix = tp.getProperty("threadNamePrefix", tp.getProperty("componentName", "Thread"));
      final String threadNameSuffix = tp.getProperty("threadNameSuffix", "");
      BlockingQueue<Runnable> queue = queueSize == 0 ? new SynchronousQueue<Runnable>() :
            new LinkedBlockingQueue<Runnable>(queueSize);
      ThreadFactory tf = new ThreadFactory() {
         @Override
         public Thread newThread(Runnable r) {
View Full Code Here

TOP

Related Classes of org.infinispan.util.TypedProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.