Skip to content

Commit

Permalink
upgrade to 1.0.2-SNAPSHOT & fix issue #1 for locate ip address for
Browse files Browse the repository at this point in the history
complex network environment
  • Loading branch information
terrymanu committed Sep 25, 2015
1 parent 69ae723 commit 59ea6a8
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 12 deletions.
2 changes: 1 addition & 1 deletion elastic-job-console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.dangdang</groupId>
<artifactId>elastic-job</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
</parent>
<artifactId>elastic-job-console</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion elastic-job-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.dangdang</groupId>
<artifactId>elastic-job</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
</parent>
<artifactId>elastic-job-core</artifactId>
<name>${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public final void execute(final JobExecutionContext context) throws JobExecution
shardingService.shardingIfNecessary();
JobExecutionMultipleShardingContext shardingContext = executionContextService.getJobExecutionShardingContext();
if (executionService.misfireIfNecessary(shardingContext.getShardingItems())) {
log.info("Previous job is still running, new job will start after previous job completed. Misfired job had recorded.");
log.info("Elastic job: previous job is still running, new job will start after previous job completed. Misfired job had recorded.");
return;
}
executionService.cleanPreviousExecutionInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public interface LocalHostService {
/**
* 获取本机IP地址.
*
* <p>
* 有限获取外网IP地址.
* 也有可能是链接着路由器的最终IP地址.
* </p>
*
* @return 本机IP地址
*/
String getIp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package com.dangdang.ddframe.job.internal.env;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;

import com.dangdang.ddframe.job.exception.JobException;

Expand All @@ -29,9 +32,45 @@
*/
public final class RealLocalHostService implements LocalHostService {

private static volatile String cachedIpAddress;

@Override
public String getIp() {
return getLocalHost().getHostAddress();
if (null != cachedIpAddress) {
return cachedIpAddress;
}
Enumeration<NetworkInterface> netInterfaces;
try {
netInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (final SocketException ex) {
throw new JobException(ex);
}
String localIpAddress = null;
while (netInterfaces.hasMoreElements()) {
NetworkInterface netInterface = netInterfaces.nextElement();
Enumeration<InetAddress> ipAddresses = netInterface.getInetAddresses();
while (ipAddresses.hasMoreElements()) {
InetAddress ipAddress = ipAddresses.nextElement();
if (isPublicIpAddress(ipAddress)) {
String publicIpAddress = ipAddress.getHostAddress();
cachedIpAddress = publicIpAddress;
return publicIpAddress;
}
if (isLocalIpAddress(ipAddress)) {
localIpAddress = ipAddress.getHostAddress();
}
}
}
cachedIpAddress = localIpAddress;
return localIpAddress;
}

private boolean isPublicIpAddress(final InetAddress ipAddress) {
return !ipAddress.isSiteLocalAddress() && !ipAddress.isLoopbackAddress() && -1 == ipAddress.getHostAddress().indexOf(":");
}

private boolean isLocalIpAddress(final InetAddress ipAddress) {
return ipAddress.isSiteLocalAddress() && !ipAddress.isLoopbackAddress() && -1 == ipAddress.getHostAddress().indexOf(":");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Collections;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

import com.dangdang.ddframe.job.api.JobConfiguration;
import com.dangdang.ddframe.job.internal.env.LocalHostService;
import com.dangdang.ddframe.job.internal.env.RealLocalHostService;
Expand All @@ -32,8 +34,6 @@
import com.dangdang.ddframe.job.schedule.JobRegistry;
import com.dangdang.ddframe.reg.base.CoordinatorRegistryCenter;

import lombok.extern.slf4j.Slf4j;

/**
* 作业失效转移服务.
*
Expand Down
4 changes: 2 additions & 2 deletions elastic-job-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.dangdang</groupId>
<artifactId>elastic-job-example</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
<name>${project.artifactId}</name>

<properties>
Expand All @@ -12,7 +12,7 @@
<project.build.locale>zh_CN</project.build.locale>
<project.nexus.address>maven.dangdang.com</project.nexus.address>

<elastic-job.version>1.0.1</elastic-job.version>
<elastic-job.version>1.0.2-SNAPSHOT</elastic-job.version>

<junit.version>4.12</junit.version>

Expand Down
2 changes: 1 addition & 1 deletion elastic-job-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.dangdang</groupId>
<artifactId>elastic-job</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
</parent>
<artifactId>elastic-job-spring</artifactId>
<name>${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) th
throw new NoSuchBeanDefinitionException("");
}
} catch (final BeansException ex) {
log.info("Cannot found bean for class: '{}'. This job is not managed for spring.", bundle.getJobDetail().getJobClass().getCanonicalName());
log.info("Elastic job: cannot found bean for class: '{}'. This job is not managed for spring.", bundle.getJobDetail().getJobClass().getCanonicalName());
return super.newJob(bundle, scheduler);
}
JobDataMap jobDataMap = new JobDataMap();
Expand Down
2 changes: 1 addition & 1 deletion elastic-job-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.dangdang</groupId>
<artifactId>elastic-job</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
</parent>
<artifactId>elastic-job-test</artifactId>
<name>${project.artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.dangdang</groupId>
<artifactId>elastic-job</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>Elastic-Job - distributed scheduled job solution</description>
Expand Down

0 comments on commit 59ea6a8

Please sign in to comment.