summaryrefslogtreecommitdiff
path: root/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/settings/ExternalSystemExecutionSettings.java
blob: f0139f09059553ab4a43426f71cca49e3f5d0682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.intellij.openapi.externalSystem.model.settings;

import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

/**
 * There is a possible case that all work with external system is performed at a separate slave process (e.g. when we use
 * an external system api and don't want to pollute ide process with it). The code which is executed at the external process
 * is unaware of any ide-local settings defined by a user then.
 * <p/>
 * Example: a user experiences problem with external system integration and we instruct him to define a dedicated system property
 * which triggers verbose processing. That property is not visible to a slave process then, so, we need to deliver the data
 * to it somehow. That's why this class has been introduced - it's just a holder for such data.
 * <p/>
 * Thread-safe.
 * 
 * @author Denis Zhdanov
 * @since 8/9/11 12:12 PM
 */
public class ExternalSystemExecutionSettings implements Serializable {

  public static final String REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY = "external.system.remote.process.idle.ttl.ms";
  private static final int    DEFAULT_REMOTE_PROCESS_TTL_MS     = 60000;

  private static final long serialVersionUID = 1L;

  @NotNull private final AtomicLong    myRemoteProcessIdleTtlInMs = new AtomicLong();
  @NotNull private final AtomicBoolean myVerboseProcessing        = new AtomicBoolean();

  @NotNull private final AtomicReference<ExternalSystemTaskNotificationListener> myNotificationListener =
    new AtomicReference<ExternalSystemTaskNotificationListener>();

  public ExternalSystemExecutionSettings() {
    int ttl = SystemProperties.getIntProperty(REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, DEFAULT_REMOTE_PROCESS_TTL_MS);
    setRemoteProcessIdleTtlInMs(ttl);
  }

  /**
   * @return ttl in milliseconds for the remote process (positive value); non-positive value if undefined
   */
  public long getRemoteProcessIdleTtlInMs() {
    return myRemoteProcessIdleTtlInMs.get();
  }

  public void setRemoteProcessIdleTtlInMs(long remoteProcessIdleTtlInMs) {
    myRemoteProcessIdleTtlInMs.set(remoteProcessIdleTtlInMs);
  }

  public boolean isVerboseProcessing() {
    return myVerboseProcessing.get();
  }

  public void setVerboseProcessing(boolean verboseProcessing) {
    myVerboseProcessing.set(verboseProcessing);
  }

  @Override
  public int hashCode() {
    int result = (int)(myRemoteProcessIdleTtlInMs.get() ^ (myRemoteProcessIdleTtlInMs.get() >>> 32));
    result = 31 * result + (myVerboseProcessing.get() ? 1 : 0);
    ExternalSystemTaskNotificationListener listener = myNotificationListener.get();
    return listener == null ? result : 31 * result + listener.hashCode();
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    ExternalSystemExecutionSettings that = (ExternalSystemExecutionSettings)o;

    if (myRemoteProcessIdleTtlInMs.get() != that.myRemoteProcessIdleTtlInMs.get()) return false;
    if (myVerboseProcessing.get() != that.myVerboseProcessing.get()) return false;
    ExternalSystemTaskNotificationListener notificationListener = myNotificationListener.get();
    ExternalSystemTaskNotificationListener thatNotificationListener = that.myNotificationListener.get();
    if ((notificationListener == null && thatNotificationListener != null)
        || (notificationListener != null && !notificationListener.equals(thatNotificationListener)))
    {
      return false;
    }

    return true;
  }
}