private void checkBeanIdentifierIndexConsistency(Map<String, Object> storage) { BeanIdentifierIndex index = getServiceRegistry().get(BeanIdentifierIndex.class); if (index != null && index.isBuilt()) { Object hash = storage.get(KEY_BEAN_ID_INDEX_HASH); if (hash != null) { if (!index.getIndexHash().equals(hash)) { throw ContextLogger.LOG.beanIdentifierIndexInconsistencyDetected(hash.toString(), index.getDebugInfo()); } } else { storage.put(KEY_BEAN_ID_INDEX_HASH, index.getIndexHash()); } } } }
/** * * @param idx * @return the identifier at the specified position */ public BeanIdentifier getIdentifier(int idx) { checkIsBuilt(); if (idx < 0 || idx >= index.length) { throw SerializationLogger.LOG.unableToGetBeanIdentifier(idx, getDebugInfo()); } return index[idx]; }
@Override public BeanIdentifier deprefix(String id) { String deprefixed = id.substring(getPrefix().length() + getDelimiter().length()); if (index == null) { return new StringBeanIdentifier(deprefixed); } if (deprefixed.startsWith(FALLBACK_FLAG)) { return new StringBeanIdentifier(deprefixed.substring(FALLBACK_FLAG.length())); } try { return index.getIdentifier(Integer.parseInt(deprefixed)); } catch (NumberFormatException e) { throw new IllegalStateException("Unable to deprefix id:" + id, e); } }
SerializableContextualHolder(String contextId, C contextual, ContextualStore contextualStore, BeanIdentifierIndex beanIdentifierIndex) { this.contextId = contextId; this.cachedContextualStore = contextualStore; if (contextual instanceof Serializable) { // the contextual is serializable, so we can just use it this.serializable = contextual; this.identifier = null; this.identifierIndex = null; } else { this.serializable = null; BeanIdentifier beanIdentifier = getId(contextual, contextualStore); // The index may be null or not built yet Integer idx = null; if (beanIdentifierIndex != null && beanIdentifierIndex.isBuilt()) { idx = beanIdentifierIndex.getIndex(beanIdentifier); } if (idx != null) { this.identifierIndex = idx; this.identifier = null; } else { this.identifierIndex = null; this.identifier = beanIdentifier; } } // cache the contextual this.cached = contextual; }
private void addImplementationServices(ServiceRegistry services) { final WeldConfiguration configuration = services.get(WeldConfiguration.class); services.add(SlimAnnotatedTypeStore.class, new SlimAnnotatedTypeStoreImpl()); if (services.get(ClassTransformer.class) == null) { throw new IllegalStateException(ClassTransformer.class.getSimpleName() + " not installed."); beanIdentifierIndex = new BeanIdentifierIndex(); services.add(BeanIdentifierIndex.class, beanIdentifierIndex); services.add(BeanDeploymentModules.class, new BeanDeploymentModules(contextId, services));
public void endInitialization() { tracker.start(Tracker.OP_END_INIT); final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class); if (index != null) { index.build(getBeansForBeanIdentifierIndex()); deploymentManager.getServices().cleanupAfterBoot(); deploymentManager.cleanupAfterBoot(); for (BeanDeployment beanDeployment : getBeanDeployments()) { BeanManagerImpl beanManager = beanDeployment.getBeanManager(); beanManager.getInterceptorMetadataReader().cleanAfterBoot(); beanManager.getServices().cleanupAfterBoot(); beanManager.cleanupAfterBoot(); final BeanDeploymentModules modules = deploymentManager.getServices().get(BeanDeploymentModules.class); if (modules != null) { modules.processBeanDeployments(getBeanDeployments()); BootstrapLogger.LOG.debugv("EE modules: {0}", modules);
if (isBuilt()) { throw new IllegalStateException("BeanIdentifier index is already built!"); tempIndex.add(((CommonBean<?>) bean).getIdentifier()); } else if (bean instanceof PassivationCapable) { tempIndex.add(new StringBeanIdentifier(((PassivationCapable) bean).getId())); if(BootstrapLogger.LOG.isDebugEnabled()) { BootstrapLogger.LOG.beanIdentifierIndexBuilt(getDebugInfo());
private void checkIsBuilt() { if (!isBuilt()) { throw new IllegalStateException("BeanIdentifier index not built!"); } }
@Override public String prefix(BeanIdentifier id) { if (index == null) { return getPrefix() + getDelimiter() + id.asString(); } Integer idx = index.getIndex(id); if (idx == null) { return getPrefix() + getDelimiter() + FALLBACK_FLAG + id.asString(); } return getPrefix() + getDelimiter() + idx; }
private void loadContextual() { if (serializable != null) { cached = serializable; } else if (identifierIndex != null) { cached = getContextualStore().<C, I> getContextual(getBeanIdentifierIndex().getIdentifier(identifierIndex)); } else if (identifier != null) { cached = getContextualStore().<C, I> getContextual(identifier); } if (cached == null) { throw new IllegalStateException("Error restoring serialized contextual with id " + identifier); } }
/** * * @param identifier * @return the position for the given bean identifier or null if the index does not contain the given identifier */ public Integer getIndex(BeanIdentifier identifier) { checkIsBuilt(); Preconditions.checkArgumentNotNull(identifier, "identifier"); return reverseIndex.get(identifier); }
public String getDebugInfo() { StringBuilder builder = new StringBuilder(); builder.append(toString()); builder.append(" \n"); for (int i = 0; i < index.length; i++) { builder.append(" "); builder.append(String.format("%4d", i)); builder.append(": "); builder.append(index[i]); builder.append("\n"); } return builder.toString(); }
private void addImplementationServices(ServiceRegistry services) { final WeldModules modules = new WeldModules(); services.add(WeldModules.class, modules); final WeldConfiguration configuration = services.get(WeldConfiguration.class); services.add(SlimAnnotatedTypeStore.class, new SlimAnnotatedTypeStoreImpl()); if (services.get(ClassTransformer.class) == null) { throw new IllegalStateException(ClassTransformer.class.getSimpleName() + " not installed."); beanIdentifierIndex = new BeanIdentifierIndex(); services.add(BeanIdentifierIndex.class, beanIdentifierIndex); services.add(ContainerLifecycleEvents.class, new ContainerLifecycleEvents(preloader, services.get(RequiredAnnotationDiscovery.class))); if (environment.isEEModulesAware()) { services.add(BeanDeploymentModules.class, new BeanDeploymentModules(contextId, services));
public void endInitialization() { tracker.start(Tracker.OP_END_INIT); final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class); if (index != null) { index.build(getBeansForBeanIdentifierIndex()); deploymentManager.getServices().cleanupAfterBoot(); deploymentManager.cleanupAfterBoot(); for (BeanDeployment beanDeployment : getBeanDeployments()) { BeanManagerImpl beanManager = beanDeployment.getBeanManager(); beanManager.getInterceptorMetadataReader().cleanAfterBoot(); beanManager.getServices().cleanupAfterBoot(); beanManager.cleanupAfterBoot(); final BeanDeploymentModules modules = deploymentManager.getServices().get(BeanDeploymentModules.class); if (modules != null) { modules.processBeanDeployments(getBeanDeployments()); BootstrapLogger.LOG.debugv("EE modules: {0}", modules);
if (isBuilt()) { throw new IllegalStateException("BeanIdentifier index is already built!"); tempIndex.add(((CommonBean<?>) bean).getIdentifier()); } else if (bean instanceof PassivationCapable) { tempIndex.add(new StringBeanIdentifier(((PassivationCapable) bean).getId())); if(BootstrapLogger.LOG.isDebugEnabled()) { BootstrapLogger.LOG.beanIdentifierIndexBuilt(getDebugInfo());
private void checkIsBuilt() { if (!isBuilt()) { throw new IllegalStateException("BeanIdentifier index not built!"); } }
SerializableContextualHolder(String contextId, C contextual, ContextualStore contextualStore, BeanIdentifierIndex beanIdentifierIndex) { this.contextId = contextId; this.cachedContextualStore = contextualStore; if (contextual instanceof Serializable) { // the contextual is serializable, so we can just use it this.serializable = contextual; this.identifier = null; this.identifierIndex = null; } else { this.serializable = null; BeanIdentifier beanIdentifier = getId(contextual, contextualStore); // The index may be null or not built yet Integer idx = null; if (beanIdentifierIndex != null && beanIdentifierIndex.isBuilt()) { idx = beanIdentifierIndex.getIndex(beanIdentifier); } if (idx != null) { this.identifierIndex = idx; this.identifier = null; } else { this.identifierIndex = null; this.identifier = beanIdentifier; } } // cache the contextual this.cached = contextual; }
@Override public String prefix(BeanIdentifier id) { if (index == null) { return getPrefix() + getDelimiter() + id.asString(); } Integer idx = index.getIndex(id); if (idx == null) { return getPrefix() + getDelimiter() + FALLBACK_FLAG + id.asString(); } return getPrefix() + getDelimiter() + idx; }
private void loadContextual() { if (serializable != null) { cached = serializable; } else if (identifierIndex != null) { cached = getContextualStore().<C, I> getContextual(getBeanIdentifierIndex().getIdentifier(identifierIndex)); } else if (identifier != null) { cached = getContextualStore().<C, I> getContextual(identifier); } if (cached == null) { throw new IllegalStateException("Error restoring serialized contextual with id " + identifier); } }
/** * * @param identifier * @return the position for the given bean identifier or null if the index does not contain the given identifier */ public Integer getIndex(BeanIdentifier identifier) { checkIsBuilt(); Preconditions.checkArgumentNotNull(identifier, "identifier"); return reverseIndex.get(identifier); }