Wicketãã¯ã©ã¹ãã¼ããå·®ãå¤ããæ¹æ³
ã¯ããã«
ãWicketãReloding対å¿ã®ããã«ã¯ã©ã¹ãã¼ããå·®ãæ¿ããæ¹æ³ã«ã¤ãã¦ãåºæ¬çãªã¨ãããã¡ã¢ãã¾ãã
ããåºæ¬çãªã¨ãããã¨æ¸ããã®ã¯ç´°é¨ã«è¬ãæ®ã£ã¦ããããã§ãã
ãç§ã®å¥½å¥å¿ãæºãããç¨åº¦ã«ã¯åãã£ãã®ã§ãã¾ãããããã¿ãããªã
å®è£ æ¹æ³ã®åºæ¬çãªã¨ãã
ãcurrentThreadã®contextClassLoaderã«ReloadingClassLoaderã®ã¤ã³ã¹ã¿ã³ã¹ãçªã£è¾¼ãã§ããã¦ãé©åãªå ´é¢ã§ãããåãåºããã¨ã«ãªãã¾ãã
ãcurrentThreadã¯Javaæ¨æºã®ã¢ã¬ã§ãã
currentThreadã®contextClassLoaderã«çªã£è¾¼ãã¿ã¤ãã³ã°
ã以ä¸ã®ï¼ã«æã§ãã
- ãã£ã«ã¿åæåæ(WicketFilter.init()ã¡ã½ãã)
- ãªã¯ã¨ã¹ããããã¨ã(WicketFilter.doGet()ã¡ã½ãã)
ãä¸è¨ã¯WicketFilter.init()ã®æç²ã§ãã
ãå¼ç¨é¨åã§getClassLoader()ã使ç¨ãã¦ãã¾ããReloadingWicketFilter使ç¨æã«ã¯getClassLoader()ã¯ReloadingClassLoaderã®ã¤ã³ã¹ã¿ã³ã¹ãè¿ãã¾ãã
ãçµæReloadingClassLoaderã®ã¤ã³ã¹ã¿ã³ã¹ããThread.currentThread().setContextClassLoader()ã¡ã½ããã®å¼æ°ã«ãªãã¾ãã
final ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader(); final ClassLoader newClassLoader = getClassLoader(); try { if (previousClassLoader != newClassLoader) { Thread.currentThread().setContextClassLoader(newClassLoader); } (以ä¸ç¥)
ãReloadingWicketFilter使ç¨æã®ã¯ã©ã¹å³ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã
ãgetClassLoader()ããªã¼ãã¼ãã¼ããããããã§ãã
ãWicketFilter.doGet()ã¡ã½ãããé¡ä¼¼ã®å¦çãè¨è¿°ããã¦ãã¾ãã
currentThreadã®contextClassLoaderããåãåºãã¨ãã
ãããããç§ã®å¥½å¥å¿ãæºãããç¨åº¦ã«ã¯åãã£ãã®ã§ããã¨æ¸ãã¦ãã¾ã£ãçç±ã ã£ãããã¾ãã
ãcurrentThreadã®contextClassLoaderãåãåºãéã«ã¯ãgetContextClassLoader()ã使ç¨ããããã§ããããå¿
ç¶æ§ããã£ã¦getContextClassLoader()ã§åãåºãã¦ãããï¼ããå
¨é¨ãã§ãã¯ããã®ã¯ã¡ãã£ã¨ãªããã¿ãããªã¨ãããããã¾ãã¦ã
ãgetContextClassLoader()ãã¯ã©ã¹ãã¼ãã欲ããã¨ãã«ã¯çµæ§æ®éã«ä½¿ãã¾ãããã
ãç¾å¨åãã£ã¦ããç¯å²ã§getContextClassLoader()ãå¿
è¦ã ã¨ç§ãè¨ããç®æã¯ãApplicationã¯ã©ã¹(å®éã«ã¯ãµãã¯ã©ã¹ã§ããã©ã)ã®ã¤ã³ã¹ã¿ã³ã¹çæã§ãã
ãããã§ãï½¢èªåãçæããã¯ã©ã¹ãã¼ãã«ã¯ã©ã¹åã®è§£æ±ºãä¾é ¼ããï½£ã¨ããJavaã®ä»æ§ãçãã¦ãã¾ãã
ãWicketãå©ç¨ãã¦ã¢ããªãæ¸ãéã«Applicationã¯ã©ã¹ãåºç¹ã«ãªããããããªãªãã¸ã§ã¯ããçæããããã§ãããã£ã¦ãApplicationãçæããã¯ã©ã¹ãã¼ããReloadingClassLoaderã«ãã¦ããã°ãAppicationã¯ã©ã¹ãçæãããªãã¸ã§ã¯ããReloadingClassLoaderã«ãã£ã¦ãã¼ããããã¯ã©ã¹ã«åºã¥ãã¦çæããã¾ããããã§ReloadingClassLoaderã®ä½¿ç¨ãä¼æãã¦ããã¾ãã
ãWicketFilter.init()ã§ã¯ããã¡ã¯ããªå
ã§getContextClassLoader()ã使ç¨ãã¦ReloadingClassLoaderãåå¾ãã¦ãã¾ãã
ãããã©ã«ãã§ã¯ContextParamWebApplicationFactory.createApplication()ã¡ã½ãããAppicationãªãã¸ã§ã¯ããçæãã¾ããä¸è¨ã«ä¸é¨æç²ãã¾ãã
protected WebApplication createApplication(final String applicationClassName) { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader == null) { loader = getClass().getClassLoader(); } final Class applicationClass = loader.loadClass(applicationClassName); if (WebApplication.class.isAssignableFrom(applicationClass)) { // Construct WebApplication subclass return (WebApplication)applicationClass.newInstance(); } (以ä¸ç¥)
æå¾ã«
ãç´°ããè¬ã¯æ®ã£ã¦ããã®ã§ãããã¯ã©ã¹ãã¼ãã®å·®ãæ¿ãã«ã¤ãã¦ã®èª¿æ»ã¯ãããã¾ã§ã«ããããã¨ä»ã¯æã£ã¦ãã¾ãã