use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.
the class WatcherSpringContext method addPath.
// Implementation
// -------------------------------------------------------------------------
protected void addPath(Path path) {
String url = null;
try {
url = toUrlString(path);
} catch (MalformedURLException e) {
LOG.warn("Ignored path " + path + " due to: " + e, e);
}
if (url != null) {
FileSystemXmlApplicationContext context = contextMap.get(url);
if (context != null) {
try {
LOG.info("Refreshing context at path " + path + " context " + context);
context.refresh();
} catch (Exception e) {
LOG.warn("Failed to refresh context at " + path + " context " + context + ". " + e, e);
}
} else {
context = createContext(path, url);
if (context != null) {
contextMap.put(url, context);
try {
LOG.info("Starting context at path " + path + " context " + context);
context.start();
} catch (Exception e) {
LOG.warn("Failed to start context at " + path + " context " + context + ". " + e, e);
}
}
}
}
}
use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.
the class FileWatcher method unscan.
private void unscan(final Path file) throws IOException {
if (isMatchesFile(file)) {
Processor processor = getProcessor();
if (processor != null) {
processor.onRemove(file);
}
lastModified = System.currentTimeMillis();
} else {
// lets find all the files that now no longer exist
List<Path> files = new ArrayList<Path>(processedMap.keySet());
for (Path path : files) {
if (!Files.exists(path)) {
LOGGER.debug("File has been deleted: " + path);
processedMap.remove(path);
if (isMatchesFile(path)) {
Processor processor = getProcessor();
if (processor != null) {
processor.onRemove(path);
}
fireListeners(path, ENTRY_DELETE);
lastModified = System.currentTimeMillis();
}
}
}
}
}
use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.
the class FileWatcherMapping method init.
public void init() throws IOException {
if (camelContext == null) {
throw new IllegalArgumentException("CamelContext must be configured on " + this);
}
mapper = new DozerBeanMapper();
setFileMatchPattern("glob:META-INF/services/dozer/*.xml");
setProcessor(new Processor() {
public void process(Path path) {
addOrUpdateMapping(path);
}
public void onRemove(Path path) {
removeMapping(path);
}
});
super.init();
LOG.info("Watching directory " + getRoot() + " for Dozer XML Mapping file changes");
}
use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.
the class ZookeeperPortService method findUsedPortByHost.
private Set<Integer> findUsedPortByHost(Container container, Lease existingLease) {
assertValid();
String ip = container.getIp();
assertValidIp(container, ip);
Set<Integer> ports = new HashSet<Integer>();
String path = ZkPath.PORTS_IP.getPath(ip);
Lease lease = null;
try {
if (existingLease != null) {
lease = existingLease;
} else {
lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
}
if (lease != null) {
createDefault(curator.get(), path, "");
String boundPorts = getStringData(curator.get(), path);
if (boundPorts != null && !boundPorts.isEmpty()) {
for (String port : boundPorts.split(" ")) {
try {
ports.add(Integer.parseInt(port.trim()));
} catch (NumberFormatException ex) {
// ignore
}
}
}
} else {
throw new FabricException("Could not acquire port lock");
}
} catch (InterruptedException ex) {
cleanUpDirtyZKNodes(interProcessLock);
throw FabricException.launderThrowable(ex);
} catch (Exception ex) {
throw FabricException.launderThrowable(ex);
} finally {
if (existingLease == null) {
releaseLock(lease);
}
}
return ports;
}
use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.
the class FabricCxfRegistrationHandler method registerApiEndpoint.
protected void registerApiEndpoint(Container container, ObjectName oName, String address, boolean started) {
String actualEndpointUrl = null;
try {
String url;
String id = container.getId();
if (isFullAddress(address)) {
url = toPublicAddress(id, address);
} else {
String cxfBus = getCxfServletPath(oName);
url = "${zk:" + id + "/http}" + cxfBus + address;
}
actualEndpointUrl = ZooKeeperUtils.getSubstitutedData(curator.get(), url);
// lets assume these locations are hard coded
// may be nice to discover from JMX one day
String apiDocPath = "/api-docs";
String wsdlPath = "?wsdl";
String wadlPath = "?_wadl";
Version version = container.getVersion();
String versionId = version != null ? version.getId() : null;
String json = "{\"id\":" + JsonHelper.jsonEncodeString(id) + ", \"container\":" + JsonHelper.jsonEncodeString(id) + ", \"version\":" + JsonHelper.jsonEncodeString(versionId) + ", \"services\":[" + JsonHelper.jsonEncodeString(url) + "]" + ", \"objectName\":" + JsonHelper.jsonEncodeString(oName.toString()) + "";
boolean rest = false;
if (booleanAttribute(oName, "isWADL")) {
rest = true;
json += ", \"wadl\":" + JsonHelper.jsonEncodeString(wadlPath);
}
if (booleanAttribute(oName, "isSwagger")) {
rest = true;
json += ", \"apidocs\":" + JsonHelper.jsonEncodeString(apiDocPath);
}
if (booleanAttribute(oName, "isWSDL")) {
json += ", \"wsdl\":" + JsonHelper.jsonEncodeString(wsdlPath);
}
json += "}";
String path = getPath(container, oName, address, rest);
LOGGER.info("Registered CXF API at " + path + " JSON: " + json);
if (!started && !rest) {
LOGGER.warn("Since the CXF service isn't started, this could really be a REST endpoint rather than WSDL at " + path);
}
registeredZkPaths.add(path);
registeredUrls.put(oName.toString(), address);
ZooKeeperUtils.setData(curator.get(), path, json, CreateMode.EPHEMERAL);
} catch (Exception e) {
LOGGER.error("Failed to register API endpoint for {}.", actualEndpointUrl, e);
}
}
Aggregations