Skip to content
Permalink
Browse files
JENKINS-30333 use direct references instead of WeakReference, added c…
…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 f238b971bca8f682040e0344dc4e8778fd7da112
Showing with 7 additions and 17 deletions.
  1. +7 −17 src/main/java/hudson/plugins/jira/JiraSite.java
@@ -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;
@@ -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,
@@ -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;
}

@@ -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;
}

/**
@@ -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);

0 comments on commit f238b97

Please sign in to comment.