Search in sources :

Example 41 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project ddf by codice.

the class HazelcastNotificationStore method getHazelcastConfig.

private Config getHazelcastConfig(BundleContext context, String xmlConfigFilename) {
    Config cfg = null;
    Bundle bundle = context.getBundle();
    URL xmlConfigFileUrl = null;
    if (StringUtils.isNotBlank(xmlConfigFilename)) {
        xmlConfigFileUrl = bundle.getResource(xmlConfigFilename);
    }
    XmlConfigBuilder xmlConfigBuilder = null;
    if (xmlConfigFileUrl != null) {
        try {
            xmlConfigBuilder = new XmlConfigBuilder(xmlConfigFileUrl.openStream());
            cfg = xmlConfigBuilder.build();
            LOGGER.debug("Successfully built hazelcast config from XML config file {}", xmlConfigFilename);
        } catch (FileNotFoundException e) {
            LOGGER.info("FileNotFoundException trying to build hazelcast config from XML file " + xmlConfigFilename, e);
            cfg = null;
        } catch (IOException e) {
            LOGGER.info("IOException trying to build hazelcast config from XML file " + xmlConfigFilename, e);
            cfg = null;
        }
    }
    if (cfg == null) {
        LOGGER.info("Falling back to using generic Config for hazelcast");
        cfg = new Config();
    } else if (LOGGER.isDebugEnabled()) {
        MapConfig mapConfig = cfg.getMapConfig("persistentNotifications");
        if (mapConfig == null) {
            LOGGER.debug("mapConfig is NULL for persistentNotifications - try persistent*");
            mapConfig = cfg.getMapConfig("persistent*");
            if (mapConfig == null) {
                LOGGER.debug("mapConfig is NULL for persistent*");
            }
        } else {
            MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
            if (mapStoreConfig != null) {
                LOGGER.debug("mapStoreConfig factoryClassName = {}", mapStoreConfig.getFactoryClassName());
            } else {
                LOGGER.debug("mapStoreConfig is null");
            }
        }
    }
    return cfg;
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) JoinConfig(com.hazelcast.config.JoinConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Bundle(org.osgi.framework.Bundle) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) URL(java.net.URL)

Example 42 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project ddf by codice.

the class ResourceCacheImpl method getHazelcastConfig.

private Config getHazelcastConfig(BundleContext context, String xmlConfigFilename) {
    Config cfg = null;
    Bundle bundle = context.getBundle();
    URL xmlConfigFileUrl = null;
    if (StringUtils.isNotBlank(xmlConfigFilename)) {
        xmlConfigFileUrl = bundle.getResource(xmlConfigFilename);
    }
    XmlConfigBuilder xmlConfigBuilder = null;
    if (xmlConfigFileUrl != null) {
        try {
            xmlConfigBuilder = new XmlConfigBuilder(xmlConfigFileUrl.openStream());
            cfg = xmlConfigBuilder.build();
            LOGGER.debug("Successfully built hazelcast config from XML config file {}", xmlConfigFilename);
        } catch (FileNotFoundException e) {
            LOGGER.info("FileNotFoundException trying to build hazelcast config from XML file " + xmlConfigFilename, e);
            cfg = null;
        } catch (IOException e) {
            LOGGER.info("IOException trying to build hazelcast config from XML file " + xmlConfigFilename, e);
            cfg = null;
        }
    }
    if (cfg == null) {
        LOGGER.info("Falling back to using generic Config for hazelcast");
        cfg = new Config();
    } else if (LOGGER.isDebugEnabled()) {
        MapConfig mapConfig = cfg.getMapConfig("Product_Cache");
        if (mapConfig == null) {
            LOGGER.debug("mapConfig is NULL for persistentNotifications - try persistent*");
            mapConfig = cfg.getMapConfig("persistent*");
            if (mapConfig == null) {
                LOGGER.debug("mapConfig is NULL for persistent*");
            }
        } else {
            MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
            if (null != mapStoreConfig) {
                LOGGER.debug("mapStoreConfig factoryClassName = {}", mapStoreConfig.getFactoryClassName());
            }
        }
    }
    return cfg;
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Bundle(org.osgi.framework.Bundle) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) URL(java.net.URL)

Example 43 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project cas by apereo.

the class HazelcastSessionConfiguration method hazelcastInstance.

/**
 * Hazelcast instance that is used by the spring session
 * repository to broadcast session events. The name
 * of this bean must be left untouched.
 *
 * @return the hazelcast instance
 */
@Bean
@SneakyThrows
public HazelcastInstance hazelcastInstance() {
    final Resource hzConfigResource = casProperties.getWebflow().getSession().getHzLocation();
    final URL configUrl = hzConfigResource.getURL();
    final Config config = new XmlConfigBuilder(hzConfigResource.getInputStream()).build();
    config.setConfigurationUrl(configUrl);
    config.setInstanceName(this.getClass().getSimpleName()).setProperty("hazelcast.logging.type", "slf4j").setProperty("hazelcast.max.no.heartbeat.seconds", "300");
    return Hazelcast.newHazelcastInstance(config);
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) Config(com.hazelcast.config.Config) Resource(org.springframework.core.io.Resource) URL(java.net.URL) SneakyThrows(lombok.SneakyThrows) Bean(org.springframework.context.annotation.Bean)

Example 44 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project openmeetings by apache.

the class Application method init.

@Override
protected void init() {
    setWicketApplicationName(super.getName());
    getSecuritySettings().setAuthenticationStrategy(new OmAuthenticationStrategy(rememberMeKey, rememberMeSalt));
    getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);
    getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
    getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
    getComponentInstantiationListeners().add(new SpringComponentInjector(this, ctx, true));
    Config cfg = new XmlConfigBuilder().build();
    cfg.setClassLoader(getClass().getClassLoader());
    hazelcast = Hazelcast.getOrCreateHazelcastInstance(cfg);
    serverId = hazelcast.getName();
    hazelcast.getCluster().getMembers().forEach(m -> cm.serverAdded(m.getAttribute(NAME_ATTR_KEY), m.getAttribute(SERVER_URL_ATTR_KEY)));
    hazelWsTopic = hazelcast.getTopic("default");
    hazelWsTopic.addMessageListener(msg -> {
        String mServerId = msg.getPublishingMember().getAttribute(NAME_ATTR_KEY);
        if (mServerId.equals(serverId)) {
            return;
        }
        IClusterWsMessage wsMsg = msg.getMessageObject();
        if (WbWebSocketHelper.send(wsMsg)) {
            return;
        }
        if (ChatWebSocketHelper.send(msg.getMessageObject())) {
            return;
        }
        WebSocketHelper.send(msg.getMessageObject());
    });
    hazelcast.getCluster().addMembershipListener(new MembershipListener() {

        @Override
        public void memberRemoved(MembershipEvent evt) {
            // server down, need to remove all online clients, process persistent addresses
            String serverId = evt.getMember().getAttribute(NAME_ATTR_KEY);
            cm.serverRemoved(serverId);
            updateJpaAddresses();
        }

        @Override
        public void memberAdded(MembershipEvent evt) {
            // no-op
            // server added, need to process persistent addresses
            updateJpaAddresses();
            // check for duplicate instance-names
            Set<String> names = new HashSet<>();
            for (Member m : evt.getMembers()) {
                if (evt.getMember().getUuid().equals(m.getUuid())) {
                    continue;
                }
                String serverId = m.getAttribute(NAME_ATTR_KEY);
                names.add(serverId);
            }
            String newServerId = evt.getMember().getAttribute(NAME_ATTR_KEY);
            log.warn("Name added: {}", newServerId);
            cm.serverAdded(newServerId, evt.getMember().getAttribute(SERVER_URL_ATTR_KEY));
            if (names.contains(newServerId)) {
                log.warn("Duplicate cluster instance with name {} found {}", newServerId, evt.getMember());
            }
        }
    });
    setPageManagerProvider(new DefaultPageManagerProvider(this) {

        @Override
        protected IPageStore newAsynchronousStore(IPageStore pageStore) {
            return new SerializingPageStore(new HazelcastDataStore(getName(), hazelcast), getFrameworkSettings().getSerializer());
        }
    });
    // Add custom resource loader at the beginning, so it will be checked first in the
    // chain of Resource Loaders, if not found it will search in Wicket's internal
    // Resource Loader for a the property key
    getResourceSettings().getStringResourceLoaders().add(0, new LabelResourceLoader());
    getRequestCycleListeners().add(new WebSocketAwareResourceIsolationRequestCycleListener() {

        @Override
        public void onBeginRequest(RequestCycle cycle) {
            String wsUrl = getWsUrl(cycle.getRequest().getUrl());
            if (wsUrl != null && !wsUrls.contains(wsUrl)) {
                wsUrls.add(wsUrl);
                cfgDao.updateCsp();
            }
        }

        @Override
        public void onEndRequest(RequestCycle cycle) {
            Response resp = cycle.getResponse();
            if (resp instanceof WebResponse) {
                WebResponse wresp = (WebResponse) resp;
                if (wresp.isHeaderSupported()) {
                    wresp.setHeader("X-XSS-Protection", "1; mode=block");
                    wresp.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
                    wresp.setHeader("X-Content-Type-Options", "nosniff");
                }
            }
        }
    });
    final WebSocketContainer sc = (WebSocketContainer) getServletContext().getAttribute(SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    if (sc != null) {
        // should be enough, should it be configurable?
        sc.setDefaultMaxSessionIdleTimeout(60 * 1000L);
    }
    getHeaderResponseDecorators().add(FilteringHeaderResponse::new);
    super.init();
    final IBootstrapSettings settings = new BootstrapSettings();
    Bootstrap.builder().withBootstrapSettings(settings).install(this);
    WysiwygLibrarySettings.get().setBootstrapCssReference(null);
    WysiwygLibrarySettings.get().setBootstrapDropDownJavaScriptReference(null);
    // register some widgets
    final DashboardContext dashboardContext = getDashboardContext();
    dashboardContext.setDashboardPersister(new UserDashboardPersister());
    WidgetRegistry widgetRegistry = dashboardContext.getWidgetRegistry();
    widgetRegistry.registerWidget(new MyRoomsWidgetDescriptor());
    widgetRegistry.registerWidget(new RecentRoomsWidgetDescriptor());
    widgetRegistry.registerWidget(new WelcomeWidgetDescriptor());
    widgetRegistry.registerWidget(new StartWidgetDescriptor());
    widgetRegistry.registerWidget(new RssWidgetDescriptor());
    widgetRegistry.registerWidget(new AdminWidgetDescriptor());
    DashboardSettings dashboardSettings = DashboardSettings.get();
    dashboardSettings.setIncludeJQueryUI(false);
    getRootRequestMapperAsCompound().add(new NoVersionMapper(getHomePage()));
    getRootRequestMapperAsCompound().add(new NoVersionMapper(NOTINIT_MAPPING, NotInitedPage.class));
    getRootRequestMapperAsCompound().add(new NoVersionMapper("denied", AccessDeniedPage.class));
    getRootRequestMapperAsCompound().add(new NoVersionMapper(HASH_MAPPING, HashPage.class));
    getRootRequestMapperAsCompound().add(new NoVersionMapper(SIGNIN_MAPPING, getSignInPageClass()));
    getRootRequestMapperAsCompound().add(new NoVersionMapper("oauth/${oauthid}", getSignInPageClass()));
    getRootRequestMapperAsCompound().add(new NoVersionMapper("privacy", PrivacyPage.class));
    mountPage("install", InstallWizardPage.class);
    mountPage("activate", ActivatePage.class);
    mountPage("reset", ResetPage.class);
    mountPage("error", InternalErrorPage.class);
    mountResource("/recordings/mp4/${id}", new Mp4RecordingResourceReference());
    // should be in sync with VideoPlayer
    mountResource("/recordings/png/${id}", new PngRecordingResourceReference());
    mountResource("/room/file/${id}", new RoomResourceReference());
    mountResource("/room/preview/${id}", new RoomPreviewResourceReference());
    mountResource("/room/file/upload", new RoomFileUploadResourceReference());
    mountResource("/admin/backup/upload", new BackupUploadResourceReference());
    mountResource("/profile/${id}", new ProfileImageResourceReference());
    mountResource("/group/${id}", new GroupLogoResourceReference());
    mountResource("/group/customcss/${id}", new GroupCustomCssResourceReference());
    mountResource("/ping", new PingResourceReference());
    log.debug("Application::init");
    try {
        if (OmFileHelper.getOmHome() == null) {
            OmFileHelper.setOmHome(new File(getServletContext().getRealPath("/")));
        }
        LabelDao.initLanguageMap();
        log.debug("webAppPath : {}", OmFileHelper.getOmHome());
        // Init all global config properties
        cfgDao.reinit();
        wbManager.init();
        cm.init();
        // Init properties
        updateJpaAddresses();
        setExtProcessTtl(cfgDao.getInt(CONFIG_EXT_PROCESS_TTL, getExtProcessTtl()));
        Version.logOMStarted();
        // we are starting so all processing recordings are now errors
        recordingDao.resetProcessingStatus();
        userManager.initHttpClient();
        setInitComplete(true);
        CompletableFuture.runAsync(() -> {
            ThreadContext.setApplication(Application.this);
            ApplicationHelper.ensureRequestCycle(Application.this);
            sipManager.setUserPicture(u -> ProfileImageResourceReference.getUrl(RequestCycle.get(), u));
        });
    } catch (Exception err) {
        log.error("[appStart]", err);
    }
}
Also used : DashboardContext(org.wicketstuff.dashboard.web.DashboardContext) DashboardSettings(org.wicketstuff.dashboard.web.DashboardSettings) RecentRoomsWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.RecentRoomsWidgetDescriptor) FilteringHeaderResponse(org.apache.wicket.markup.head.filter.FilteringHeaderResponse) MyRoomsWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.MyRoomsWidgetDescriptor) IBootstrapSettings(de.agilecoders.wicket.core.settings.IBootstrapSettings) BootstrapSettings(de.agilecoders.wicket.core.settings.BootstrapSettings) PrivacyPage(org.apache.openmeetings.web.pages.PrivacyPage) PingResourceReference(org.apache.openmeetings.web.common.PingResourceReference) Member(com.hazelcast.cluster.Member) MeetingMember(org.apache.openmeetings.db.entity.calendar.MeetingMember) RoomPreviewResourceReference(org.apache.openmeetings.web.room.RoomPreviewResourceReference) IPageStore(org.apache.wicket.pageStore.IPageStore) WelcomeWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.WelcomeWidgetDescriptor) Mp4RecordingResourceReference(org.apache.openmeetings.web.user.record.Mp4RecordingResourceReference) RoomResourceReference(org.apache.openmeetings.web.room.RoomResourceReference) SerializingPageStore(org.apache.wicket.pageStore.SerializingPageStore) RoomFileUploadResourceReference(org.apache.openmeetings.web.room.sidebar.RoomFileUploadResourceReference) GroupLogoResourceReference(org.apache.openmeetings.web.util.GroupLogoResourceReference) File(java.io.File) UserDashboardPersister(org.apache.openmeetings.web.util.UserDashboardPersister) ProfileImageResourceReference(org.apache.openmeetings.web.util.ProfileImageResourceReference) GroupCustomCssResourceReference(org.apache.openmeetings.web.room.GroupCustomCssResourceReference) Set(java.util.Set) HashSet(java.util.HashSet) Config(com.hazelcast.config.Config) MembershipEvent(com.hazelcast.cluster.MembershipEvent) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) BackupUploadResourceReference(org.apache.openmeetings.web.admin.backup.BackupUploadResourceReference) WebSocketAwareResourceIsolationRequestCycleListener(org.apache.wicket.protocol.ws.WebSocketAwareResourceIsolationRequestCycleListener) HazelcastDataStore(org.wicketstuff.datastores.hazelcast.HazelcastDataStore) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) WebResponse(org.apache.wicket.request.http.WebResponse) WebSocketContainer(javax.websocket.WebSocketContainer) AdminWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.admin.AdminWidgetDescriptor) RssWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.RssWidgetDescriptor) NotInitedPage(org.apache.openmeetings.web.pages.NotInitedPage) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) UnknownHostException(java.net.UnknownHostException) WebResponse(org.apache.wicket.request.http.WebResponse) Response(org.apache.wicket.request.Response) FilteringHeaderResponse(org.apache.wicket.markup.head.filter.FilteringHeaderResponse) HashPage(org.apache.openmeetings.web.pages.HashPage) StartWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.StartWidgetDescriptor) IBootstrapSettings(de.agilecoders.wicket.core.settings.IBootstrapSettings) WidgetRegistry(org.wicketstuff.dashboard.WidgetRegistry) IClusterWsMessage(org.apache.openmeetings.util.ws.IClusterWsMessage) AccessDeniedPage(org.apache.openmeetings.web.pages.AccessDeniedPage) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector) MembershipListener(com.hazelcast.cluster.MembershipListener) PngRecordingResourceReference(org.apache.openmeetings.web.user.record.PngRecordingResourceReference) DefaultPageManagerProvider(org.apache.wicket.DefaultPageManagerProvider)

Example 45 with XmlConfigBuilder

use of com.hazelcast.config.XmlConfigBuilder in project hazelcast-simulator by hazelcast.

the class Hazelcast3Driver method startDriverInstance.

@Override
public void startDriverInstance() throws Exception {
    String workerType = get("WORKER_TYPE");
    LOGGER.info(format("%s HazelcastInstance starting", workerType));
    if ("javaclient".equals(workerType)) {
        File configFile = new File(getUserDir(), "client-hazelcast.xml");
        XmlClientConfigBuilder configBuilder = new XmlClientConfigBuilder(configFile);
        ClientConfig clientConfig = configBuilder.build();
        hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
    } else {
        File configFile = new File(getUserDir(), "hazelcast.xml");
        XmlConfigBuilder configBuilder = new XmlConfigBuilder(configFile.getAbsolutePath());
        Config config = configBuilder.build();
        hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    }
    LOGGER.info(format("%s HazelcastInstance started", workerType));
    warmupPartitions(hazelcastInstance);
    LOGGER.info("Warmed up partitions");
}
Also used : XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) File(java.io.File) FileUtils.getConfigurationFile(com.hazelcast.simulator.utils.FileUtils.getConfigurationFile)

Aggregations

XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)50 Config (com.hazelcast.config.Config)43 InputStream (java.io.InputStream)17 ClientConfig (com.hazelcast.client.config.ClientConfig)15 Test (org.junit.Test)14 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)13 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)12 Before (org.junit.Before)11 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 JoinConfig (com.hazelcast.config.JoinConfig)7 AwsConfig (com.hazelcast.config.AwsConfig)6 InterfacesConfig (com.hazelcast.config.InterfacesConfig)6 MulticastConfig (com.hazelcast.config.MulticastConfig)6 TcpIpConfig (com.hazelcast.config.TcpIpConfig)6 File (java.io.File)6 MapConfig (com.hazelcast.config.MapConfig)5 Member (com.hazelcast.cluster.Member)4 MapStoreConfig (com.hazelcast.config.MapStoreConfig)4