Skip to content

Commit 195945f

Browse files
authored
Merge pull request #23 from neuland/hmc-reset-locked
do both update and hmc reset in a 'locked' context (uses reflections)
2 parents dd87429 + 68bd67a commit 195945f

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

src/de/neuland/firefly/HybrisAdapter.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import de.hybris.platform.core.Initialization;
44
import de.hybris.platform.core.PK;
55
import de.hybris.platform.core.Registry;
6+
import de.hybris.platform.core.system.InitializationLockHandler;
7+
import de.hybris.platform.core.system.impl.DefaultInitLockDao;
68
import de.hybris.platform.regioncache.CacheController;
79
import de.hybris.platform.servicelayer.event.EventService;
810
import de.hybris.platform.util.JspContext;
@@ -13,11 +15,18 @@
1315
import org.springframework.mock.web.MockHttpServletResponse;
1416
import org.springframework.stereotype.Component;
1517

18+
import java.lang.reflect.Method;
19+
import java.util.concurrent.Callable;
20+
21+
import static java.lang.String.format;
22+
1623

1724
@Component
1825
@Scope("prototype")
1926
public class HybrisAdapter {
2027
private static final Logger LOG = Logger.getLogger(HybrisAdapter.class);
28+
private static final String SYSTEM_UPDATE = "System update";
29+
private static final String HMC_RESET = "HMC Reset";
2130
@Autowired EventService eventService;
2231
@Autowired CacheController cacheController;
2332

@@ -53,12 +62,34 @@ private void doInitialize(boolean update) throws Exception {
5362
request.addParameter("clearHMC", "true");
5463

5564
JspContext jspContext = new JspContext(jspWriter, request, new MockHttpServletResponse());
56-
Initialization.doInitialize(jspContext);
65+
66+
try {
67+
InitializationLockHandler handler = new InitializationLockHandler(new DefaultInitLockDao());
68+
String operationName = update ? SYSTEM_UPDATE : HMC_RESET;
69+
70+
handler.performLocked(Registry.getCurrentTenant(),
71+
createInitializeCallable(jspContext),
72+
operationName);
73+
} catch (NoSuchMethodException e) {
74+
LOG.info(format("Internal reflection unsuccessful: system is not locked while performing '%s only' change.", HMC_RESET));
75+
Initialization.doInitialize(jspContext);
76+
}
5777
} finally {
5878
LOG.debug(de.hybris.platform.util.Utilities.filterOutHTMLTags(jspWriter.getString()));
5979
}
6080
}
6181

82+
private Callable<Boolean> createInitializeCallable(final JspContext jspContext) {
83+
return new Callable<Boolean>() {
84+
public Boolean call() throws Exception {
85+
Method m = Initialization.class.getDeclaredMethod("doInitializeImpl", JspContext.class);
86+
m.setAccessible(true);
87+
m.invoke(null, jspContext);
88+
return Boolean.TRUE;
89+
}
90+
};
91+
}
92+
6293
public void clearHmcConfiguration(PK migration) throws Exception {
6394
doInitialize(false);
6495
eventService.publishEvent(new HmcResetEvent(getTenantId(), migration));

0 commit comments

Comments
 (0)