/** * Returns a specific bean given its name * * @param name * @return */ public static final Object bean(String name) { return bean(name, context); }
XMLConfiguration getXmlConfiguration() { XMLConfiguration mainConfig = GeoWebCacheExtensions.bean(XMLConfiguration.class); return mainConfig; }
/** * Looks up the {@link XMLConfiguration} from the spring context. * * @deprecated Only to be used for testing * @return The {@link XMLConfiguration} */ @Deprecated XMLConfiguration getXmlConfiguration() { XMLConfiguration mainConfig = GeoWebCacheExtensions.bean(XMLConfiguration.class); return mainConfig; }
CompositeBlobStore getCompositeBlobStore() { CompositeBlobStore compositeBlobStore = GeoWebCacheExtensions.bean(CompositeBlobStore.class); checkNotNull(compositeBlobStore); return compositeBlobStore; }
private static String resolveFromEnv(String str) { if (gwcEnvironment == null) { gwcEnvironment = GeoWebCacheExtensions.bean(GeoWebCacheEnvironment.class); } if (gwcEnvironment != null && str != null && GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION) { Object result = gwcEnvironment.resolveValue(str); if (result == null) { return null; } return result.toString(); } return str; }
/** * Loads a single bean by its type. * * <p>This method returns null if there is no such bean. An exception is thrown if multiple * beans of the specified type exist. * * @param type THe type of the bean to lookup. * @throws IllegalArgumentException If there are multiple beans of the specified type in the * context. */ public static final <T> T bean(Class<T> type) throws IllegalArgumentException { checkContext(context); return context != null ? bean(type, context) : null; }
private static String resolveFromEnv(String str) { if (gwcEnvironment == null) { gwcEnvironment = GeoWebCacheExtensions.bean(GeoWebCacheEnvironment.class); } if (gwcEnvironment != null && str != null && GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION) { Object result = gwcEnvironment.resolveValue(str); if (result == null) { return null; } return result.toString(); } return str; }
/** * Retrieves the configured {@link LockProvider} bean based on the lock provider bean name * ({@link #lockProvider}). * * @return The LockProvider bean, or a new {@link MemoryLockProvider} if no bean of the given * name was found */ @Override public LockProvider getLockProvider() { if (this.lockProvider != null) { LockProvider lockProviderBean = (LockProvider) GeoWebCacheExtensions.bean(this.lockProvider); if (lockProviderBean != null) { return lockProviderBean; } } return new MemoryLockProvider(); }
/** * Sets the lock provider bean name ({@link #lockProvider}) based on the provided {@link * LockProvider} bean. If the passed lockProvider is not a bean, sets the bean name to null. * * @param lockProvider The lock provider bean * @throws IOException */ @Override public void setLockProvider(LockProvider lockProvider) throws IOException { // default to null this.lockProvider = null; if (lockProvider != null) { String[] lockProviderNames = GeoWebCacheExtensions.getBeansNamesOrderedByPriority(LockProvider.class); for (String beanName : lockProviderNames) { if (lockProvider.equals(GeoWebCacheExtensions.bean(beanName))) { this.lockProvider = beanName; } } } }
private void truncate( GWC mediator, Context geogigContext, LayerInfo layer, Optional<Ref> oldValue, Optional<Ref> newValue) { GeoServerTileLayer tileLayer = mediator.getTileLayer(layer); if (tileLayer == null) { return; } TileBreeder breeder = GeoWebCacheExtensions.bean(TileBreeder.class); checkState(breeder != null); // if GWC wasn't installed it should have returned earlier TruncateHelper.issueTruncateTasks(geogigContext, oldValue, newValue, tileLayer, breeder); }
/** * Returns the chosen lock provider * * @see ServerConfiguration#getLockProvider() * @return */ public LockProvider getLockProvider() { if (lockProviderInstance == null) { if (lockProvider == null) { lockProviderInstance = new MemoryLockProvider(); } else { Object provider = GeoWebCacheExtensions.bean(lockProvider); if (provider == null) { throw new RuntimeException( "Could not find lock provider " + lockProvider + " in the spring application context"); } else if (!(provider instanceof LockProvider)) { throw new RuntimeException( "Found bean " + lockProvider + " in the spring application context, but it was not a LockProvider"); } else { lockProviderInstance = (LockProvider) provider; } } } return lockProviderInstance; }
/** * * Reinitialization is tricky, because we can't really just lock all the blobstores, because * this would cause people to queue on something that we may not want to exist post reinit. * * <p>So we'll just set the current blobstore set free, ready for garbage collection, and * generate a new one. */ public void reInit() { List<BlobStoreConfiguration> extensions = GeoWebCacheExtensions.extensions(BlobStoreConfiguration.class); this.configs = new ArrayList<BlobStoreConfiguration>(extensions); this.layers = GeoWebCacheExtensions.bean(TileLayerDispatcher.class); initialize(); } /**
public static DiskQuotaConfig loadConfiguration(final Reader reader, XStream xstream) { DiskQuotaConfig fromXML = (DiskQuotaConfig) xstream.fromXML(reader); final GeoWebCacheEnvironment gwcEnvironment = GeoWebCacheExtensions.bean(GeoWebCacheEnvironment.class); if (gwcEnvironment != null && GeoWebCacheEnvironment.ALLOW_ENV_PARAMETRIZATION) { fromXML.setQuotaStore((String) gwcEnvironment.resolveValue(fromXML.getQuotaStore())); } return fromXML; }
/** * Updates the configurable lock provider to use the specified bean * * @param lockProviderName */ private void updateLockProvider(String lockProviderName) { LockProvider delegate = null; if (lockProviderName == null) { delegate = new MemoryLockProvider(); } else { Object provider = GeoWebCacheExtensions.bean(lockProviderName); if (provider == null) { throw new RuntimeException( "Could not find lock provider " + lockProvider + " in the spring application context"); } else if (!(provider instanceof LockProvider)) { throw new RuntimeException( "Found bean " + lockProvider + " in the spring application context, but it was not a LockProvider"); } else { delegate = (LockProvider) provider; } } lockProvider.setDelegate(delegate); }
public GwcServiceProxy() { serviceInfo = new ServiceInfoImpl(); serviceInfo.setId("gwc"); serviceInfo.setName("gwc"); serviceInfo.setEnabled(true); serviceInfo.setVersions(ImmutableList.of(new Version("1.0.0"))); gwcDispatcher = GeoWebCacheExtensions.bean(GeoWebCacheDispatcher.class); }
public GwcServiceProxy() { serviceInfo = new ServiceInfoImpl(); serviceInfo.setId("gwc"); serviceInfo.setName("gwc"); serviceInfo.setEnabled(true); serviceInfo.setVersions(ImmutableList.of(new Version("1.0.0"))); gwcDispatcher = GeoWebCacheExtensions.bean(GeoWebCacheDispatcher.class); }
@Test public void testBeanString() { ApplicationContext appContext = createMock(ApplicationContext.class); GeoWebCacheExtensions gse = new GeoWebCacheExtensions(); gse.setApplicationContext(null); assertNull(GeoWebCacheExtensions.bean("beanName")); gse.setApplicationContext(appContext); expect(appContext.getBean("beanName")).andReturn(null); // call #1 expect(appContext.getBean("beanName")).andReturn(this); // call #2 replay(appContext); assertNull(GeoWebCacheExtensions.bean("beanName")); // call #1 assertSame(this, GeoWebCacheExtensions.bean("beanName")); // call #2 verify(appContext); }
@Override public void evaluate() throws Throwable { String bean = "THISISTHEBEAN"; rule.addBean("foo", bean, String.class); assertThat(GeoWebCacheExtensions.bean("foo"), sameInstance(bean)); } },
@Override public void evaluate() throws Throwable { String bean = "THISISTHEBEAN"; rule.addBean("foo", bean, String.class); assertThat( GeoWebCacheExtensions.bean(String.class), sameInstance(bean)); } },
public void testRemoveLayerAfterReload() throws Exception { Catalog cat = getCatalog(); TileLayerDispatcher tld = GeoWebCacheExtensions.bean(TileLayerDispatcher.class); LayerInfo li = cat.getLayerByName(super.getLayerId(MockData.MPOINTS)); String layerName = tileLayerName(li); assertNotNull(tld.getTileLayer(layerName)); // force reload getGeoServer().reload(); // now remove the layer and check it has been removed from GWC as well cat.remove(li); try { tld.getTileLayer(layerName); fail("Layer should not exist"); } catch (GeoWebCacheException gwce) { // fine } } }