+ public void start(BundleContext bundleContext) throws Exception {
+ instance = this;
+ this.bc = bundleContext;
+ this.logReaderService = getService(LogReaderService.class);
+ // this.configurationAdmin = getService(ConfigurationAdmin.class);
+
+ initSecurity();// must be first
+ initArgeoLogger();
+ try {
+ initNode();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new CmsException("Cannot initialize node", e);
+ }
+ }
+
+ private void initSecurity() {
+ URL url = getClass().getClassLoader().getResource(
+ KernelConstants.JAAS_CONFIG);
+ System.setProperty("java.security.auth.login.config",
+ url.toExternalForm());
+ }
+
+ private void initArgeoLogger() {
+ logger = new NodeLogger(logReaderService);
+ bc.registerService(ArgeoLogger.class, logger, null);
+ }
+
+ private void initNode() throws IOException {
+ // Node state
+ Path stateUuidPath = bc.getDataFile("stateUuid").toPath();
+ String stateUuid;
+ if (Files.exists(stateUuidPath)) {
+ stateUuid = Files.readAllLines(stateUuidPath).get(0);
+ } else {
+ stateUuid = bc.getProperty(Constants.FRAMEWORK_UUID);
+ Files.write(stateUuidPath, stateUuid.getBytes());
+ }
+ nodeState = new CmsState(stateUuid);
+ Dictionary<String, Object> regProps = LangUtils.dico(
+ Constants.SERVICE_PID, NodeConstants.NODE_STATE_PID);
+ regProps.put(NodeConstants.CN, stateUuid);
+ bc.registerService(NodeState.class, nodeState, regProps);