use of java.lang.System.Logger.Level.INFO in project piranha by piranhacloud.
the class MicroInnerDeployer method start.
/**
* Start the application.
*
* @param applicationArchive the application archive.
* @param classLoader the classloader.
* @param handlers the handlers.
* @param config the configuration.
* @return the map.
*/
public Map<String, Object> start(Archive<?> applicationArchive, ClassLoader classLoader, Map<String, Function<URL, URLConnection>> handlers, Map<String, Object> config) {
try {
WebApplication webApplication = getWebApplication(applicationArchive, classLoader);
LOGGER.log(INFO, "Starting web application " + applicationArchive.getName() + " on Piranha Micro " + webApplication.getAttribute(MICRO_PIRANHA));
// The global archive stream handler is set to resolve "shrinkwrap://" URLs (created from strings).
// Such URLs come into being primarily when code takes resolves a class or resource from the class loader by URL
// and then takes the string form of the URL representing the class or resource.
GlobalArchiveStreamHandler streamHandler = new GlobalArchiveStreamHandler(webApplication);
// Life map to the StaticURLStreamHandlerFactory used by the root class loader
handlers.put("shrinkwrap", streamHandler::connect);
// Source of annotations
Index index = getIndex();
// Target of annotations
AnnotationManager annotationManager = new InternalAnnotationScanAnnotationManager();
webApplication.getManager().setAnnotationManager(annotationManager);
// Copy annotations from our "annotations" collection from source index to target manager
forEachWebAnnotation(webAnnotation -> addAnnotationToIndex(index, webAnnotation, annotationManager));
// Collect sub-classes/interfaces of our "instances" collection from source index to target manager
forEachInstance(instanceClass -> addInstanceToIndex(index, instanceClass, annotationManager));
// Collect any sub-classes/interfaces from any HandlesTypes annotation
getAnnotations(index, HandlesTypes.class).map(this::getTarget).forEach(annotationTarget -> getAnnotationInstances(annotationTarget, HandlesTypes.class).map(HandlesTypes.class::cast).forEach(handlesTypesInstance -> stream(handlesTypesInstance.value()).forEach(e -> {
if (e.isAnnotation()) {
addAnnotationToIndex(index, e, annotationManager);
} else {
addInstanceToIndex(index, e, annotationManager);
}
})));
// Setup the default identity store, which is used as the default "username and roles database" for
// (Servlet) security.
initIdentityStore(webApplication);
setApplicationContextPath(webApplication, config, applicationArchive);
DefaultWebApplicationExtensionContext extensionContext = new DefaultWebApplicationExtensionContext();
for (WebApplicationExtension extension : ServiceLoader.load(WebApplicationExtension.class)) {
extensionContext.add(extension);
}
extensionContext.configure(webApplication);
webApplication.initialize();
webApplication.start();
if ((boolean) config.get("micro.http.start")) {
HttpWebApplicationServer webApplicationServer = new HttpWebApplicationServer();
webApplicationServer.addWebApplication(webApplication);
ServiceLoader<HttpServer> httpServers = ServiceLoader.load(HttpServer.class);
httpServer = httpServers.findFirst().orElseThrow();
httpServer.setServerPort((Integer) config.get("micro.port"));
httpServer.setSSL(Boolean.getBoolean("piranha.http.ssl"));
httpServer.setHttpServerProcessor(webApplicationServer);
httpServer.start();
}
return Map.of("deployedServlets", webApplication.getServletRegistrations().keySet(), "deployedApplication", new MicroInnerApplication(webApplication), "deployedContextRoot", webApplication.getContextPath());
} catch (IOException e) {
throw new IllegalStateException(e);
} catch (Exception e) {
throw e;
}
}
use of java.lang.System.Logger.Level.INFO in project tcMenu by davetcc.
the class NewProjectController method onCreate.
public void onCreate(ActionEvent actionEvent) {
boolean newOnlyMode = newOnlyRadio.isSelected();
if (newOnlyMode) {
if (!passDirtyCheck())
return;
project.newProject();
} else if (maybeDirectory.isPresent() && !StringHelper.isStringEmptyOrNull(projectNameField.getText())) {
if (!passDirtyCheck())
return;
try {
String projName = projectNameField.getText();
var projectCreator = new CreateProjectCommand();
projectCreator.createNewProject(Paths.get(maybeDirectory.get()), projName, cppMainCheckbox.isSelected(), platformCombo.getSelectionModel().getSelectedItem(), s -> logger.log(INFO, s), namespaceField.getText());
Path emfFileName = Paths.get(maybeDirectory.get(), projName, projName + ".emf");
project.openProject(emfFileName.toString());
} catch (Exception e) {
logger.log(ERROR, "Failure processing create new project", e);
var alert = new Alert(Alert.AlertType.ERROR, "Error during create project", ButtonType.CLOSE);
BaseDialogSupport.getJMetro().setScene(alert.getDialogPane().getScene());
alert.showAndWait();
}
} else {
var alert = new Alert(Alert.AlertType.WARNING, "Please ensure all fields are populated", ButtonType.CLOSE);
BaseDialogSupport.getJMetro().setScene(alert.getDialogPane().getScene());
alert.showAndWait();
// avoid closing.
return;
}
Stage stage = (Stage) createButton.getScene().getWindow();
stage.close();
}
use of java.lang.System.Logger.Level.INFO in project tcMenu by davetcc.
the class GenerateCodeDialog method ensureIoFullyDeclared.
private void ensureIoFullyDeclared(CodePluginItem pluginItem) {
logger.log(INFO, "Checking for unmapped IO devices: " + pluginItem.getDescription());
var codeOptions = project.getGeneratorOptions();
// find any IO device declarations that do not match to an entry in the expanders
var anyIoWithoutEntries = pluginItem.getProperties().stream().filter(prop -> prop.getValidationRules() instanceof IoExpanderPropertyValidationRules).filter(prop -> codeOptions.getExpanderDefinitions().getDefinitionById(prop.getLatestValue()).isEmpty()).toList();
// nothing to do if list is empty
if (anyIoWithoutEntries.isEmpty()) {
logger.log(INFO, "All IO devices mapped");
return;
}
var allExpanders = new HashSet<>(codeOptions.getExpanderDefinitions().getAllExpanders());
// now we iterate through the unmapped expanders, which must be from prior to the automated support.
for (var customIo : anyIoWithoutEntries) {
if (StringHelper.isStringEmptyOrNull(customIo.getLatestValue())) {
// for empty strings, the previous assumption was using device IO. This is now explicitly defined
// as deviceIO
customIo.setLatestValue(InternalDeviceExpander.DEVICE_ID);
logger.log(INFO, "Device being mapped as internal: " + customIo.getLatestValue());
} else {
// otherwise, previously the assumption was using a custom defined expander in the sketch, now we'll
// actually add that to the sketch.
allExpanders.add(new CustomDeviceExpander(customIo.getLatestValue()));
logger.log(INFO, "Device being mapped as custom: " + customIo.getLatestValue());
}
}
project.setGeneratorOptions(new CodeGeneratorOptionsBuilder().withExisting(codeOptions).withExpanderDefinitions(new IoExpanderDefinitionCollection(allExpanders)).codeOptions());
logger.log(INFO, "Done mapping all IO devices");
}
use of java.lang.System.Logger.Level.INFO in project tcMenu by davetcc.
the class PropertiesAuthenticator method addAuthentication.
/**
* Adds an authentication token to the store, it assumes that all appropriate permission from the user has
* been sought.
* @param user the user to add
* @param uuid the uuid associated with the user
* @return
*/
@Override
public CompletableFuture<Boolean> addAuthentication(String user, UUID uuid) {
if (dialogManager == null)
return CompletableFuture.completedFuture(false);
return CompletableFuture.supplyAsync(() -> {
try {
logger.log(INFO, "Request for authentication with " + user);
var shouldProceed = new AtomicBoolean(false);
var dialogLatch = new CountDownLatch(1);
dialogManager.withTitle("Pair with " + user, true).withMessage("Be sure you know where this connection originated", true).withDelegate(DialogViewer.DialogShowMode.REGULAR, menuButtonType -> {
shouldProceed.set(menuButtonType == MenuButtonType.ACCEPT);
dialogLatch.countDown();
return true;
}).showDialogWithButtons(MenuButtonType.ACCEPT, MenuButtonType.CANCEL);
if (!dialogLatch.await(30, TimeUnit.SECONDS)) {
logger.log(INFO, "Dialog Latch timed out without user operation");
}
if (shouldProceed.get()) {
synchronized (properties) {
Path pathLocation = Path.of(location);
properties.setProperty(user, uuid.toString());
properties.store(Files.newBufferedWriter(pathLocation, CREATE, TRUNCATE_EXISTING), "TcMenu Auth properties");
}
logger.log(INFO, "Wrote auth properties to ", location);
return true;
} else {
logger.log(INFO, "Pairing dialog was not accepted");
return false;
}
} catch (Exception e) {
logger.log(ERROR, "Failed to write auth properties to ", location);
return false;
}
});
}
use of java.lang.System.Logger.Level.INFO in project piranha by piranhacloud.
the class IsolatedServerPiranha method run.
/**
* Start method.
*/
@Override
public void run() {
long startTime = System.currentTimeMillis();
LOGGER.log(INFO, () -> "Starting Piranha");
webApplicationServer = new HttpWebApplicationServer();
HttpServer httpServer = ServiceLoader.load(HttpServer.class).findFirst().orElseThrow();
httpServer.setServerPort(8080);
httpServer.setHttpServerProcessor(webApplicationServer);
httpServer.setSSL(ssl);
httpServer.start();
webApplicationServer.start();
File[] webapps = new File("webapps").listFiles();
if (webapps != null) {
if (webapps.length != 0) {
// Limit threads used by Weld, since default is Runtime.getRuntime().availableProcessors(), which is per deployment.
int threadsPerApp = Math.max(2, Runtime.getRuntime().availableProcessors() / webapps.length);
System.setProperty("org.jboss.weld.executor.threadPoolSize", threadsPerApp + "");
}
File deployingFile = createDeployingFile();
Arrays.stream(webapps).parallel().filter(warFile -> warFile.getName().toLowerCase().endsWith(".war")).forEach(warFile -> deploy(warFile, webApplicationServer));
try {
Files.delete(deployingFile.toPath());
} catch (IOException ioe) {
LOGGER.log(WARNING, "Unable to delete deploying file", ioe);
}
}
long finishTime = System.currentTimeMillis();
LOGGER.log(INFO, "Started Piranha");
LOGGER.log(INFO, "It took {0} milliseconds", finishTime - startTime);
File startedFile = createStartedFile();
File pidFile = new File("tmp/piranha.pid");
while (httpServer.isRunning()) {
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
if (!pidFile.exists()) {
webApplicationServer.stop();
httpServer.stop();
try {
Files.delete(startedFile.toPath());
} catch (IOException ioe) {
LOGGER.log(WARNING, "Unable to delete PID file", ioe);
}
System.exit(0);
}
}
finishTime = System.currentTimeMillis();
LOGGER.log(INFO, "Stopped Piranha");
LOGGER.log(INFO, "We ran for {0} milliseconds", finishTime - startTime);
}
Aggregations