Skip to content

Commit

Permalink
JENKINS-30333 use direct references instead of WeakReference, added c…
Browse files Browse the repository at this point in the history
…reateSession logging

Conflicts:
	src/main/java/hudson/plugins/jira/JiraSite.java
  • Loading branch information
gerhard6 authored and Radek Antoniuk committed Sep 15, 2015
1 parent 3413f8c commit f238b97
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/main/java/hudson/plugins/jira/JiraSite.java
Expand Up @@ -23,7 +23,6 @@
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -139,7 +138,7 @@ public class JiraSite extends AbstractDescribableImpl<JiraSite> {
*/
private transient Lock projectUpdateLock = new ReentrantLock();

private transient ThreadLocal<WeakReference<JiraSession>> jiraSession = new ThreadLocal<WeakReference<JiraSession>>();
private transient JiraSession jiraSession = null;

@DataBoundConstructor
public JiraSite(URL url, URL alternativeUrl, String userName, String password, boolean supportsWikiStyleComment, boolean recordScmChanges, String userPattern,
Expand Down Expand Up @@ -175,14 +174,13 @@ public JiraSite(URL url, URL alternativeUrl, String userName, String password, b
this.groupVisibility = Util.fixEmpty(groupVisibility);
this.roleVisibility = Util.fixEmpty(roleVisibility);
this.useHTTPAuth = useHTTPAuth;
this.jiraSession.set(new WeakReference<JiraSession>(null));
this.jiraSession = null;
}

protected Object readResolve() {
projectUpdateLock = new ReentrantLock();
issueCache = makeIssueCache();
jiraSession = new ThreadLocal<WeakReference<JiraSession>>();
jiraSession.set(new WeakReference<JiraSession>(null));
jiraSession = null;
return this;
}

Expand All @@ -203,20 +201,11 @@ public String getName() {
*/
@Nullable
public JiraSession getSession() throws IOException {
JiraSession session = null;

WeakReference<JiraSession> weakReference = jiraSession.get();
if (weakReference != null) {
session = weakReference.get();
if (jiraSession == null) {
jiraSession = createSession();
}

if (session == null) {
// TODO: we should check for session timeout, too
// Currently no real problem, as we're using a weak reference for the session, so it will be GC'ed very quickly
session = createSession();
jiraSession.set(new WeakReference<JiraSession>(session));
}
return session;
return jiraSession;
}

/**
Expand All @@ -237,6 +226,7 @@ private JiraSession createSession() throws IOException {
LOGGER.warning("convert URL to URI error: " + e.getMessage());
throw new RuntimeException("failed to create JiraSession due to convert URI error");
}
LOGGER.info("creating Jira Session: " + uri);

final JiraRestClient jiraRestClient = new AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(uri, userName, password);
Expand Down

0 comments on commit f238b97

Please sign in to comment.