/** * Returns true if the persisted version is compatible with the * current version of this storage hook. The default implementation * returns true if the specified version is identical to the current * version. Implementations must override this method if they * want to support other (older) versions for migration purposes. * @param version the persisted version * @return true if the persisted version is compatible with * the current version. */ public boolean isCompatibleWith(int version) { return getStorageVersion() == version; }
@SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); if (next.getKey().equals(factoryName)) { factory = next; iFactories.remove(); DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes)); try { if (factory.isCompatibleWith(version)) { Object loadContext = factory.createLoadContext(version); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.load(loadContext, temp); getHooks(hookMap, generation).add(hook); continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.initialize(generation.getHeaders()); getHooks(hookMap, generation).add(hook); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); try { hook.initialize(generation.getHeaders());
private void saveStorageHookData(DataOutputStream out, List<Generation> generations) throws IOException { List<StorageHookFactory<?, ?, ?>> factories = getConfiguration().getHookRegistry().getStorageHookFactories(); out.writeInt(factories.size()); for (StorageHookFactory<?, ?, ?> factory : factories) { out.writeUTF(factory.getKey()); out.writeInt(factory.getStorageVersion()); // create a temporary in memory stream so we can figure out the length ByteArrayOutputStream tempBytes = new ByteArrayOutputStream(); DataOutputStream temp = new DataOutputStream(tempBytes); try { Object saveContext = factory.createSaveContext(); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle } @SuppressWarnings({"rawtypes", "unchecked"}) StorageHook<Object, Object> hook = generation.getStorageHook((Class) factory.getClass()); hook.save(saveContext, temp); } } finally { temp.close(); } out.writeInt(tempBytes.size()); out.write(tempBytes.toByteArray()); } }
private void setStorageHooks(Generation generation) throws BundleException { if (generation.getBundleInfo().getBundleId() == 0) { return; // ignore system bundle } List<StorageHookFactory<?, ?, ?>> factories = new ArrayList<StorageHookFactory<?, ?, ?>>(getConfiguration().getHookRegistry().getStorageHookFactories()); List<StorageHook<?, ?>> hooks = new ArrayList<StorageHook<?, ?>>(factories.size()); for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) { @SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); hooks.add(hook); } generation.setStorageHooks(Collections.unmodifiableList(hooks), true); for (StorageHook<?, ?> hook : hooks) { hook.initialize(generation.getHeaders()); } }
/** * Creates a storage hook for the specified generation and checks that the * factory class of the storage hook equals the class of this storage hook * factory. * * @param generation - The generation for which a storage hook should be * created. * @return A newly created storage hook. * @throws IllegalStateException - If the factory class of the storage hook * is not equal to the class of this storage hook factory. */ public final H createStorageHookAndValidateFactoryClass(Generation generation) { H result = createStorageHook(generation); Class<?> factoryClass = getClass(); Class<?> factoryClassOfStorageHook = result.getFactoryClass(); if (!factoryClass.equals(factoryClassOfStorageHook)) throw new IllegalStateException(String.format("The factory class '%s' of storage hook '%s' does not match the creating factory class of '%s'", factoryClassOfStorageHook.getName(), result, factoryClass.getName())); //$NON-NLS-1$ return result; }
@SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); if (next.getKey().equals(factoryName)) { factory = next; iFactories.remove(); DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes)); try { if (factory.isCompatibleWith(version)) { Object loadContext = factory.createLoadContext(version); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.load(loadContext, temp); getHooks(hookMap, generation).add(hook); continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.initialize(generation.getHeaders()); getHooks(hookMap, generation).add(hook); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); try { hook.initialize(generation.getHeaders());
private void saveStorageHookData(DataOutputStream out, List<Generation> generations) throws IOException { List<StorageHookFactory<?, ?, ?>> factories = getConfiguration().getHookRegistry().getStorageHookFactories(); out.writeInt(factories.size()); for (StorageHookFactory<?, ?, ?> factory : factories) { out.writeUTF(factory.getKey()); out.writeInt(factory.getStorageVersion()); // create a temporary in memory stream so we can figure out the length ByteArrayOutputStream tempBytes = new ByteArrayOutputStream(); DataOutputStream temp = new DataOutputStream(tempBytes); try { Object saveContext = factory.createSaveContext(); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle } @SuppressWarnings({"rawtypes", "unchecked"}) StorageHook<Object, Object> hook = generation.getStorageHook((Class) factory.getClass()); hook.save(saveContext, temp); } } finally { temp.close(); } out.writeInt(tempBytes.size()); out.write(tempBytes.toByteArray()); } }
private void setStorageHooks(Generation generation) throws BundleException { if (generation.getBundleInfo().getBundleId() == 0) { return; // ignore system bundle } List<StorageHookFactory<?, ?, ?>> factories = new ArrayList<>(getConfiguration().getHookRegistry().getStorageHookFactories()); List<StorageHook<?, ?>> hooks = new ArrayList<>(factories.size()); for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) { @SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); hooks.add(hook); } generation.setStorageHooks(Collections.unmodifiableList(hooks), true); for (StorageHook<?, ?> hook : hooks) { hook.initialize(generation.getHeaders()); } }
/** * Creates a storage hook for the specified generation and checks that the * factory class of the storage hook equals the class of this storage hook * factory. * * @param generation - The generation for which a storage hook should be * created. * @return A newly created storage hook. * @throws IllegalStateException - If the factory class of the storage hook * is not equal to the class of this storage hook factory. */ public final H createStorageHookAndValidateFactoryClass(Generation generation) { H result = createStorageHook(generation); Class<?> factoryClass = getClass(); Class<?> factoryClassOfStorageHook = result.getFactoryClass(); if (!factoryClass.equals(factoryClassOfStorageHook)) throw new IllegalStateException(String.format("The factory class '%s' of storage hook '%s' does not match the creating factory class of '%s'", factoryClassOfStorageHook.getName(), result, factoryClass.getName())); //$NON-NLS-1$ return result; }
@SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); if (next.getKey().equals(factoryName)) { factory = next; iFactories.remove(); DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes)); try { if (factory.isCompatibleWith(version)) { Object loadContext = factory.createLoadContext(version); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.load(loadContext, temp); getHooks(hookMap, generation).add(hook); continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.initialize(generation.getHeaders()); getHooks(hookMap, generation).add(hook); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); try { hook.initialize(generation.getHeaders());
private void saveStorageHookData(DataOutputStream out, List<Generation> generations) throws IOException { List<StorageHookFactory<?, ?, ?>> factories = getConfiguration().getHookRegistry().getStorageHookFactories(); out.writeInt(factories.size()); for (StorageHookFactory<?, ?, ?> factory : factories) { out.writeUTF(factory.getKey()); out.writeInt(factory.getStorageVersion()); // create a temporary in memory stream so we can figure out the length ByteArrayOutputStream tempBytes = new ByteArrayOutputStream(); DataOutputStream temp = new DataOutputStream(tempBytes); try { Object saveContext = factory.createSaveContext(); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle } @SuppressWarnings({"rawtypes", "unchecked"}) StorageHook<Object, Object> hook = generation.getStorageHook((Class) factory.getClass()); hook.save(saveContext, temp); } } finally { temp.close(); } out.writeInt(tempBytes.size()); out.write(tempBytes.toByteArray()); } }
/** * Returns true if the persisted version is compatible with the * current version of this storage hook. The default implementation * returns true if the specified version is identical to the current * version. Implementations must override this method if they * want to support other (older) versions for migration purposes. * @param version the persisted version * @return true if the persisted version is compatible with * the current version. */ public boolean isCompatibleWith(int version) { return getStorageVersion() == version; }
private void setStorageHooks(Generation generation) throws BundleException { if (generation.getBundleInfo().getBundleId() == 0) { return; // ignore system bundle } List<StorageHookFactory<?, ?, ?>> factories = new ArrayList<StorageHookFactory<?, ?, ?>>(getConfiguration().getHookRegistry().getStorageHookFactories()); List<StorageHook<?, ?>> hooks = new ArrayList<StorageHook<?, ?>>(factories.size()); for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) { @SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); hooks.add(hook); } generation.setStorageHooks(Collections.unmodifiableList(hooks), true); for (StorageHook<?, ?> hook : hooks) { hook.initialize(generation.getHeaders()); } }
/** * Creates a storage hook for the specified generation and checks that the * factory class of the storage hook equals the class of this storage hook * factory. * * @param generation - The generation for which a storage hook should be * created. * @return A newly created storage hook. * @throws IllegalStateException - If the factory class of the storage hook * is not equal to the class of this storage hook factory. */ public final H createStorageHookAndValidateFactoryClass(Generation generation) { H result = createStorageHook(generation); Class<?> factoryClass = getClass(); Class<?> factoryClassOfStorageHook = result.getFactoryClass(); if (!factoryClass.equals(factoryClassOfStorageHook)) throw new IllegalStateException(String.format("The factory class '%s' of storage hook '%s' does not match the creating factory class of '%s'", factoryClassOfStorageHook.getName(), result, factoryClass.getName())); //$NON-NLS-1$ return result; }
@SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); if (next.getKey().equals(factoryName)) { factory = next; iFactories.remove(); DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes)); try { if (factory.isCompatibleWith(version)) { Object loadContext = factory.createLoadContext(version); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.load(loadContext, temp); getHooks(hookMap, generation).add(hook); continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.initialize(generation.getHeaders()); getHooks(hookMap, generation).add(hook); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); try { hook.initialize(generation.getHeaders());
private void saveStorageHookData(DataOutputStream out, List<Generation> generations) throws IOException { List<StorageHookFactory<?, ?, ?>> factories = getConfiguration().getHookRegistry().getStorageHookFactories(); out.writeInt(factories.size()); for (StorageHookFactory<?, ?, ?> factory : factories) { out.writeUTF(factory.getKey()); out.writeInt(factory.getStorageVersion()); // create a temporary in memory stream so we can figure out the length ByteArrayOutputStream tempBytes = new ByteArrayOutputStream(); DataOutputStream temp = new DataOutputStream(tempBytes); try { Object saveContext = factory.createSaveContext(); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle } @SuppressWarnings({"rawtypes", "unchecked"}) StorageHook<Object, Object> hook = generation.getStorageHook((Class) factory.getClass()); hook.save(saveContext, temp); } } finally { temp.close(); } out.writeInt(tempBytes.size()); out.write(tempBytes.toByteArray()); } }
/** * Returns true if the persisted version is compatible with the * current version of this storage hook. The default implementation * returns true if the specified version is identical to the current * version. Implementations must override this method if they * want to support other (older) versions for migration purposes. * @param version the persisted version * @return true if the persisted version is compatible with * the current version. */ public boolean isCompatibleWith(int version) { return getStorageVersion() == version; }
private void setStorageHooks(Generation generation) throws BundleException { if (generation.getBundleInfo().getBundleId() == 0) { return; // ignore system bundle } List<StorageHookFactory<?, ?, ?>> factories = new ArrayList<StorageHookFactory<?, ?, ?>>(getConfiguration().getHookRegistry().getStorageHookFactories()); List<StorageHook<?, ?>> hooks = new ArrayList<StorageHook<?, ?>>(factories.size()); for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) { @SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); hooks.add(hook); } generation.setStorageHooks(Collections.unmodifiableList(hooks), true); for (StorageHook<?, ?> hook : hooks) { hook.initialize(generation.getHeaders()); } }
/** * Creates a storage hook for the specified generation and checks that the * factory class of the storage hook equals the class of this storage hook * factory. * * @param generation - The generation for which a storage hook should be * created. * @return A newly created storage hook. * @throws IllegalStateException - If the factory class of the storage hook * is not equal to the class of this storage hook factory. */ public final H createStorageHookAndValidateFactoryClass(Generation generation) { H result = createStorageHook(generation); Class<?> factoryClass = getClass(); Class<?> factoryClassOfStorageHook = result.getFactoryClass(); if (!factoryClass.equals(factoryClassOfStorageHook)) throw new IllegalStateException(String.format("The factory class '%s' of storage hook '%s' does not match the creating factory class of '%s'", factoryClassOfStorageHook.getName(), result, factoryClass.getName())); //$NON-NLS-1$ return result; }
@SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next(); if (next.getKey().equals(factoryName)) { factory = next; iFactories.remove(); DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes)); try { if (factory.isCompatibleWith(version)) { Object loadContext = factory.createLoadContext(version); for (Generation generation : generations) { if (generation.getBundleInfo().getBundleId() == 0) { continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.load(loadContext, temp); getHooks(hookMap, generation).add(hook); continue; // ignore system bundle StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation); hook.initialize(generation.getHeaders()); getHooks(hookMap, generation).add(hook); StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation); try { hook.initialize(generation.getHeaders());