/** * Returns a managed object for accessing OSGi service(s). * * @return managed OSGi service(s) */ public Object getObject() { if (!initialized) throw new FactoryBeanNotInitializedException(); if (proxy == null) { synchronized (this) { if (proxy == null) { proxy = createProxy(false); } } } if (lazyProxy) { synchronized (this) { if (lazyProxy) { getProxyInitializer().run(); lazyProxy = false; } } } return proxy; }
/** * Return the singleton instance of this class's proxy object, * lazily creating it if it hasn't been created already. * @return the shared singleton proxy */ private synchronized Object getSingletonInstance() { if (this.singletonInstance == null) { this.targetSource = freshTargetSource(); if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) { // Rely on AOP infrastructure to tell us what interfaces to proxy. Class<?> targetClass = getTargetClass(); if (targetClass == null) { throw new FactoryBeanNotInitializedException("Cannot determine target class for proxy"); } setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader)); } // Initialize the shared singleton instance. super.setFrozen(this.freezeProxy); this.singletonInstance = getProxy(createAopProxy()); } return this.singletonInstance; }
/** * Return the singleton instance of this class's proxy object, * lazily creating it if it hasn't been created already. * @return the shared singleton proxy */ private synchronized Object getSingletonInstance() { if (this.singletonInstance == null) { this.targetSource = freshTargetSource(); if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) { // Rely on AOP infrastructure to tell us what interfaces to proxy. Class targetClass = getTargetClass(); if (targetClass == null) { throw new FactoryBeanNotInitializedException("Cannot determine target class for proxy"); } setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader)); } // Initialize the shared singleton instance. super.setFrozen(this.freezeProxy); this.singletonInstance = getProxy(createAopProxy()); } return this.singletonInstance; }
@Override public Object getObject() throws Exception { if (clazz == null) { throw new FactoryBeanNotInitializedException( "The factory is not fully initialized yet, i.e. no class is defined by '" + beanClass + "'."); } if (singleton) { if (created == null) { created = createInstance(); } return created; } else { return createInstance(); } }
@Override public Object getObject() throws BeansException { if (this.beanFactory == null) { throw new FactoryBeanNotInitializedException(); } return this.beanFactory.getBean(this.targetBeanName); }
@Override public boolean isSingleton() { if (this.beanFactory == null) { throw new FactoryBeanNotInitializedException(); } return this.beanFactory.isSingleton(this.targetBeanName); }
@Override public boolean isPrototype() { if (this.beanFactory == null) { throw new FactoryBeanNotInitializedException(); } return this.beanFactory.isPrototype(this.targetBeanName); }
/** * Determine an 'eager singleton' instance, exposed in case of a * circular reference. Not called in a non-circular scenario. */ @SuppressWarnings("unchecked") private T getEarlySingletonInstance() throws Exception { Class<?>[] ifcs = getEarlySingletonInterfaces(); if (ifcs == null) { throw new FactoryBeanNotInitializedException( getClass().getName() + " does not support circular references"); } if (this.earlySingletonInstance == null) { this.earlySingletonInstance = (T) Proxy.newProxyInstance( this.beanClassLoader, ifcs, new EarlySingletonInvocationHandler()); } return this.earlySingletonInstance; }
@Override public Object getObject() throws IllegalAccessException { if (this.fieldObject == null) { throw new FactoryBeanNotInitializedException(); } ReflectionUtils.makeAccessible(this.fieldObject); if (this.targetObject != null) { // instance field return this.fieldObject.get(this.targetObject); } else{ // class field return this.fieldObject.get(null); } }
/** * Returns the same value each time if the singleton property is set * to "true", otherwise returns the value returned from invoking the * specified method on the fly. */ @Override public Object getObject() throws Exception { if (this.singleton) { if (!this.initialized) { throw new FactoryBeanNotInitializedException(); } // Singleton: return shared object. return this.singletonObject; } else { // Prototype: new object on each call. return invokeWithTargetException(); } }
@Override public Object getObject() { if (this.proxy == null) { throw new FactoryBeanNotInitializedException(); } return this.proxy; }
@Override public IStorage getObject() throws Exception { if (storage == null) { throw new FactoryBeanNotInitializedException(); } return storage; }
@Override public Object getObject() throws IllegalAccessException { if (this.fieldObject == null) { throw new FactoryBeanNotInitializedException(); } ReflectionUtils.makeAccessible(this.fieldObject); if (this.targetObject != null) { // instance field return this.fieldObject.get(this.targetObject); } else { // class field return this.fieldObject.get(null); } }
/** * To get single bean of the specified type. * @param type Class<T> * @param <T> * @return <T> */ public static <T> T get(final Class<T> type) { if (applicationContext == null) { LOGGER.error("Ephesoft application Context yet not initialized."); throw new FactoryBeanNotInitializedException("Ephesoft application Context yet not initialized."); } return ApplicationContextUtil.getSingleBeanOfType(applicationContext, type); }
public void afterPropertiesSet() throws Exception { if (ArrayUtils.isEmpty(getProxyInterfaces())) { setProxyInterfaces(detectProxyInterfaces()); if (ArrayUtils.isEmpty(getProxyInterfaces())) { throw new FactoryBeanNotInitializedException("Failed to initialize factory bean because " + "proxyInterfaces were not injected or could not be derived from object type."); } } this.proxyObject = Proxy.newProxyInstance(getClass().getClassLoader(), getProxyInterfaces(), new LazyInvocationHandler()); }
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (beanFactory instanceof ListableBeanFactory) { this.beanFactory = (ListableBeanFactory) beanFactory; } else { throw new FactoryBeanNotInitializedException(String.format("BeanFactory must be instance of '%s'", ListableBeanFactory.class.getSimpleName())); } }
/** * Determine an 'eager singleton' instance, exposed in case of a * circular reference. Not called in a non-circular scenario. */ @SuppressWarnings("unchecked") private T getEarlySingletonInstance() throws Exception { Class[] ifcs = getEarlySingletonInterfaces(); if (ifcs == null) { throw new FactoryBeanNotInitializedException( getClass().getName() + " does not support circular references"); } if (this.earlySingletonInstance == null) { this.earlySingletonInstance = (T) Proxy.newProxyInstance( this.beanClassLoader, ifcs, new EarlySingletonInvocationHandler()); } return this.earlySingletonInstance; }
public Object getObject() throws IllegalAccessException { if (this.fieldObject == null) { throw new FactoryBeanNotInitializedException(); } ReflectionUtils.makeAccessible(this.fieldObject); if (this.targetObject != null) { // instance field return this.fieldObject.get(this.targetObject); } else{ // class field return this.fieldObject.get(null); } }
/** * Returns the same value each time if the singleton property is set * to "true", otherwise returns the value returned from invoking the * specified method on the fly. */ public Object getObject() throws Exception { if (this.singleton) { if (!this.initialized) { throw new FactoryBeanNotInitializedException(); } // Singleton: return shared object. return this.singletonObject; } else { // Prototype: new object on each call. return doInvoke(); } }
/** * Returns a managed object for accessing OSGi service(s). * * @return managed OSGi service(s) */ public Object getObject() { if (!initialized) throw new FactoryBeanNotInitializedException(); if (proxy == null) { proxy = createProxy(); } return proxy; }
@Override public Object getObject() throws IOException { String[] urls = StringUtils.split(cacheLocations, ", "); List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>(); for (String url : urls) { int colonIndex = url.indexOf(":"); String host = url.substring(0, colonIndex); int port = NumberUtils.toInt(url.substring(colonIndex + 1, url.length())); if(port==0) { throw new FactoryBeanNotInitializedException("invalid port: cacheLocations=" + cacheLocations); } InetSocketAddress address = new InetSocketAddress(host, port); addresses.add(address); } long timeout = Math.max(readTimeout, writeTimeout); //TODO make all the below properties configurable via properties file ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder() .setOpTimeout(timeout) .setDaemon(true) .setProtocol(Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.KETAMA_HASH) .setFailureMode(FailureMode.Retry) .setInitialObservers(Collections.singleton((ConnectionObserver) new MemcachedAlerter())); if(transcoder!=null) { builder.setTranscoder(transcoder); } ConnectionFactory connectionFactory = builder.build(); return new MemcachedClient(connectionFactory, addresses); }
@Override public Object getObject() { String[] urls = StringUtils.split(cacheLocations, ","); String[] weights = StringUtils.split(weightOfHosts, ","); if (urls.length < weights.length) { throw new FactoryBeanNotInitializedException("invalid number of weights: weightOfHosts= " + weightOfHosts + " (Number of weights > Number of urls)"); } List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); long timeout = Math.max(readTimeout, writeTimeout); for ( int i = 0; i < urls.length; i++) { int colonIndex = urls[i].indexOf(":"); String host = urls[i].substring(0, colonIndex); int port = NumberUtils.toInt(urls[i].substring(colonIndex + 1, urls[i].length())); if(port==0) { throw new FactoryBeanNotInitializedException("invalid port: cacheLocations=" + cacheLocations); } if( weights[i] == null) { weights[i] = "1"; } int weight = Integer.parseInt(weights[i]); JedisShardInfo jedisShardInfo = new JedisShardInfo(host, port, (int) timeout,weight); shards.add(jedisShardInfo); } MurmurHash murmurHash = new MurmurHash(); ShardedJedis jedisClient = new ShardedJedis(shards,murmurHash); return jedisClient; }
public Object getObject() throws Exception { if (ldapOperations==null) { throw new FactoryBeanNotInitializedException("contextSource ldapOperations property has not been set"); } if (managedClasses==null) { throw new FactoryBeanNotInitializedException("managedClasses property has not been set"); } if (converterManager==null) { throw new FactoryBeanNotInitializedException("converterManager property has not been set"); } return new OdmManagerImpl(converterManager, ldapOperations, managedClasses); }