final String key = (String)ois.readObject();
final Object value = ois.readObject();
binaryProperties.put(key, value);
}
} catch (final ClassNotFoundException cnfe) {
throw new PersistenceException("Class not found.", cnfe);
} catch (final java.io.InvalidClassException ice) {
throw new PersistenceException("Invalid class.", ice);
} catch (final IOException ioe) {
throw new PersistenceException("Unable to deserialize job properties.", ioe);
} finally {
try {
ois.close();
} catch (final IOException ioe) {
throw new PersistenceException("Unable to deserialize job properties.", ioe);
}
}
}
final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
properties.put(JobImpl.PROPERTY_BRIDGED_EVENT, true);
final String topic = (String)properties.remove("slingevent:topic");
properties.put(ResourceHelper.PROPERTY_JOB_TOPIC, topic);
properties.remove(Job.PROPERTY_JOB_QUEUE_NAME);
properties.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
// and binary properties
properties.putAll(binaryProperties);
properties.remove("slingevent:properties");
if ( !properties.containsKey(Job.PROPERTY_JOB_RETRIES) ) {
properties.put(Job.PROPERTY_JOB_RETRIES, 10); // we put a dummy value here; this gets updated by the queue
}
if ( !properties.containsKey(Job.PROPERTY_JOB_RETRY_COUNT) ) {
properties.put(Job.PROPERTY_JOB_RETRY_COUNT, 0);
}
final List<InstanceDescription> potentialTargets = caps.getPotentialTargets("/", null);
String targetId = null;
if ( potentialTargets != null && potentialTargets.size() > 0 ) {
final QueueInfo info = configuration.getQueueConfigurationManager().getQueueInfo(topic);
logger.debug("Found queue {} for {}", info.queueConfiguration, topic);
targetId = caps.detectTarget(topic, vm, info);
if ( targetId != null ) {
properties.put(Job.PROPERTY_JOB_QUEUE_NAME, info.queueName);
properties.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
properties.put(Job.PROPERTY_JOB_RETRIES, info.queueConfiguration.getMaxRetries());
}
}
properties.put(Job.PROPERTY_JOB_CREATED_INSTANCE, "old:" + Environment.APPLICATION_ID);
properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, ResourceHelper.RESOURCE_TYPE_JOB);
final String jobId = configuration.getUniqueId(topic);
properties.put(ResourceHelper.PROPERTY_JOB_ID, jobId);
properties.remove(Job.PROPERTY_JOB_STARTED_TIME);
final String newPath = configuration.getUniquePath(targetId, topic, jobId, vm);
this.logger.debug("Moving 'old' job from {} to {}", jobResource.getPath(), newPath);
ResourceHelper.getOrCreateResource(resolver, newPath, properties);
resolver.delete(jobResource);
resolver.commit();
} catch (final InstantiationException ie) {
throw new PersistenceException("Exception while reading reasource: " + ie.getMessage(), ie.getCause());
}
}