Java Code Examples for com.jeesuite.common.util.ResourceUtils#getBoolean()

The following examples show how to use com.jeesuite.common.util.ResourceUtils#getBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EurekaRegistry.java    From oneplatform with Apache License 2.0 5 votes vote down vote up
private void initEurekaClient(Properties properties) throws Exception{
	
	properties.setProperty("eureka.metadataMap.nodeId", NodeNameHolder.getNodeId());
	ConfigurationManager.loadProperties(properties);
	//ConfigurationManager.loadPropertiesFromResources("eureka.properties");
	
	//DynamicPropertyFactory configInstance = com.netflix.config.DynamicPropertyFactory.getInstance();
	
	MyDataCenterInstanceConfig instanceConfig = new MyDataCenterInstanceConfig(){
		@Override
		public String getHostName(boolean refresh) {
			String hostName = super.getHostName(refresh);
			if(ResourceUtils.getBoolean("eureka.preferIpAddress")){
				hostName = IpUtils.getLocalIpAddr();
			}
			return hostName;
		}

		@Override
		public String getIpAddress() {
			return IpUtils.getLocalIpAddr();
		}
		
		
	};
	InstanceInfo instanceInfo = new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get();
       applicationInfoManager = new ApplicationInfoManager(instanceConfig, instanceInfo);
       
       DefaultEurekaClientConfig clientConfig = new DefaultEurekaClientConfig();

       eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig);
       
       instanceId = instanceInfo.getInstanceId();
}
 
Example 2
Source File: RequestLimitFilter.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldFilter() {
	return ResourceUtils.getBoolean(REQUEST_LIMIT_ENABLED_KEY);
}
 
Example 3
Source File: ZkJobRegistry.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
       if(ResourceUtils.getBoolean("jeesuite.task.registry.disabled", false)){
       	return;
       }
	ZkConnection zkConnection = new ZkConnection(zkServers);
	zkClient = new ZkClient(zkConnection, 10000);
	//
	zkCheckTask = Executors.newScheduledThreadPool(1);

	zkCheckTask.scheduleAtFixedRate(new Runnable() {
		@Override
		public void run() {
			if (schedulerConfgs.isEmpty())
				return;
			List<String> activeNodes = null;
			try {
				activeNodes = zkClient.getChildren(nodeStateParentPath);
				zkAvailabled = true;
			} catch (Exception e) {
				checkZkAvailabled();
				activeNodes = new ArrayList<>(JobContext.getContext().getActiveNodes());
			}

			if (!activeNodes.contains(JobContext.getContext().getNodeId())) {
				zkClient.createEphemeral(nodeStateParentPath + "/" + JobContext.getContext().getNodeId());
				logger.info("node[{}] re-join task clusters", JobContext.getContext().getNodeId());
			}
			// 对节点列表排序
			Collections.sort(activeNodes);
			// 本地缓存的所有jobs
			Collection<JobConfig> jobConfigs = schedulerConfgs.values();
			//
			for (JobConfig jobConfig : jobConfigs) {
				// 如果本地任务指定的执行节点不在当前实际的节点列表,重新指定
				if (!activeNodes.contains(jobConfig.getCurrentNodeId())) {
					// 指定当前节点为排序后的第一个节点
					String newExecuteNodeId = activeNodes.get(0);
					jobConfig.setCurrentNodeId(newExecuteNodeId);
					logger.warn("Job[{}-{}] currentNodeId[{}] not in activeNodeList, assign new ExecuteNodeId:{}",
							jobConfig.getGroupName(), jobConfig.getJobName(), jobConfig.getCurrentNodeId(),
							newExecuteNodeId);
				}
			}
		}
	}, 60, 30, TimeUnit.SECONDS);
}
 
Example 4
Source File: JobContext.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
public void setRegistry(JobRegistry registry) {
	if(ResourceUtils.getBoolean("jeesuite.task.registry.disabled", false)){
       	return;
       }
	this.registry = registry;
}
 
Example 5
Source File: ConfigcenterContext.java    From jeesuite-config with Apache License 2.0 3 votes vote down vote up
public synchronized void init(Properties properties,boolean isSpringboot) {
	if(processed || !isRemoteEnabled())return;
	ResourceUtils.merge(properties);
	
	System.setProperty("client.nodeId", nodeId);
	System.setProperty("springboot", String.valueOf(isSpringboot));
	this.isSpringboot = isSpringboot;
	String defaultAppName = ResourceUtils.getProperty("spring.application.name");
	app = ResourceUtils.getProperty("jeesuite.configcenter.appName",defaultAppName);
	if(remoteEnabled == null)remoteEnabled = ResourceUtils.getBoolean("jeesuite.configcenter.enabled",true);
	
	if(!isRemoteEnabled())return;
	
	env = ResourceUtils.getProperty("jeesuite.configcenter.profile","dev");
	
	Validate.notBlank(env,"[jeesuite.configcenter.profile] is required");
	
	setApiBaseUrl(ResourceUtils.getProperty("jeesuite.configcenter.base.url"));
	
	version = ResourceUtils.getProperty("jeesuite.configcenter.version","0.0.0");
	
	syncIntervalSeconds = ResourceUtils.getInt("jeesuite.configcenter.sync-interval-seconds", 30);
	
	tokenCryptKey = ResourceUtils.getProperty("jeesuite.configcenter.cryptKey");
	
	System.out.println(String.format("\n=====Configcenter config=====\nappName:%s\nenv:%s\nversion:%s\nremoteEnabled:%s\napiBaseUrls:%s\n=====Configcenter config=====", app,env,version,isRemoteEnabled(),JsonUtils.toJson(apiBaseUrls)));
	
}