
ããã§ã¯ãOdnoklassnikiãããžã§ã¯ãã®ããŸããŸãªãµãŒãã¹ã®éçºã«åœ¹ç«ã€å€ãã®ããŒã«ã®1ã€ã®ããã€ã¹ã«ã€ããŠèª¬æããŸãã 瀟å
ã§ã¯ããããã³ãŒã眮æãïŒHCRïŒãšåŒã°ãããã®ããŒã«ã¯ãéçšãµãŒãã¹ã忢ããããšãªãå®è¡ããéã®é倧ã§åçŽãªãã°ãä¿®æ£ããããã«èšèšãããŠããŸãã ããã¯éåžžã«éèŠãªæ©èœã§ããããã¯ãä¿®æ£ãããæ°ããããŒãžã§ã³ã®ãžã£ã³ã¯ãµãŒãã¹ãã¬ã€ã¢ãŠããããšããããªãéå±ã§æéã®ãããããã»ã¹ãåé¿ããåãã¹ãã®å¯çšæ§ã®ã¢ãã³ãã³ããååã«é·ãé忢ããã®ãåé¿ãããã£ãã·ã¥ã®ãã©ãã·ã¥ãåé¿ã§ããããã§ãã
äžè¬ã«ãå€ãã®æéãç¯çŽãããšã©ãŒãæ€åºãããç¬éããä¿®æ£ãŸã§ã®ééãæ°æéããæ°åã«ççž®ããŸãã ã»ãšãã©ã®å Žåãèšç»ã©ãããã³ãŒãã®è»œåŸ®ãªãšã©ãŒãä¿®æ£ãããŸããããšãã°ãããã°ã©ããŒãnullããã§ãã¯ããã®ãå¿ããäžéšã®ãŠãŒã¶ãŒã¯ãµã€ãã§ã®ç¹å®ã®ã¢ã¯ã·ã§ã³ã«ãã£ãŠãšã©ãŒãçºçããŸãã ã€ãŸããã¡ãœããå
ã®è€æ°ã®è¡ã倿ŽããŠä¿®æ£ãå®è¡ããå Žåã§ãã ãŸãããã®ãããªå°ããªå€æŽã®ããã«ãååã®æ³šæãããããçç£ã®ããã«äœæéãæéããããå¿
èŠããªããªããŸããã
äŸïŒ

ç°¡åã«ä¿®æ£ã§ããŸãïŒ

ãã¡ãããæ¬¡ã®æŽæ°ãåŸ
ããã«ãã¯ããã«å€ãã®å€æŽãå ããåæã«æ°ããã¯ã©ã¹ã远å ãããããŒãžã£ãŒãåæã«èŠæ±ãã倿Žããã°ããè¡ãããšãã§ããŸãã ããããããã¯ãã§ã«ãã ãã·ã¥ãŒãåé¯ã«ã€ããŠå€ãã®ããšãç¥ã£ãŠãããªãã§ãã
ããã«ãäºãã«ããããããç¡éã«é
眮ããããšãã§ããŸãã
ãã ãããã®ããŒã«ã¯å
šèœã§ã¯ãªããJavaã¯ã©ã¹ãæäŸããæšæºæ©èœ
java.lang.instrument.Instrumentationãšãã®ã¡ãœããvoid redefineClassesïŒClassDefinition ... definitionsïŒã«åºã¥ããŠããŸãã
Instrumentation.redefineClassesã¯ã以åã«ããŒããããã¯ã©ã¹ãæ°ãããã€ãã³ãŒãã«çœ®ãæããŸãã ç°ãªãäŸåé¢ä¿ãæã€è€æ°ã®ã¯ã©ã¹ãåæã«ãªãŒããŒããŒãã§ããŸãã ãªãŒããŒããŒãã¯ãæ¢åã®ã¯ã©ã¹ã€ã³ã¹ã¿ã³ã¹ã倿Žãããç¶æ¿ã倿Žãããã€ã³ã¹ã¿ã³ã¹ãŸãã¯ã¯ã©ã¹ãã£ãŒã«ãã«åœ±é¿ããŸããã ã¡ãœããã®æ¬äœã宿°ãšå±æ§ã®ããŒã«ã®ã¿ã倿Žã§ããŸãã æ°ããã¯ã©ã¹ãŸãã¯ãµãã¯ã©ã¹ã远å ã§ããŸãã ã¡ãœããã·ã°ããã£ãã€ã³ã¹ã¿ã³ã¹ãã£ãŒã«ããããã³ã¯ã©ã¹ãã£ãŒã«ãã¯å€æŽã§ããŸããã äºææ§ã®ãªã倿Žãè¡ãããšãããšãredefineClassesã¯ååãšããŠæ©èœããããšã©ãŒãã¹ããŒããŸãã ã¯ã©ã¹ããªãŒããŒããŒãããããšãã³ãŒãã®ãªãŒããŒããŒããããã»ã¯ã·ã§ã³ã®å®è¡ãäžæããããæ¬¡ååãã¡ãœãããåŒã³åºããããšãã«æ°ãããã€ãã³ãŒãã䜿çšãããããšã«æ³šæããŠãã ããã ãããã£ãŠãå
éšã«ç¡éã«é·ããµã€ã¯ã«ãããã¡ãœããã®ã³ãŒããä¿®æ£ããããšãããšãå®éã®çœ®æã¯ãã®ãµã€ã¯ã«ãçµäºããåŸã«ã®ã¿çºçããŸãã
éåžžã«åçŽãªå ŽåïŒã¡ãœãããšãã€ã³ãå
ã§ã®ã¿ã³ãŒãã倿Žã§ããŸãã
ãããŠãã¡ãœãããå®äºãããŸã§ä¿®æ£ãããªãwhileã«ãŒãã®äŸã次ã«ç€ºããŸãã

äž»ãªå°é£ã¯ã確ç«ããããã¹ãŠã®äœæ¥ããã»ã¹ã«é©åããããŒã«ã§ããOdnoklassnikiãšã³ã·ã¹ãã ã§æ©èœããããŒã«ãäœæããããšã§ããã ããã¯ãäœçŸãã®ãã¹ãäžã®ãã¹ãŠã®ãµãŒãã¹ãšäžè²«ããŠééçã«å¯Ÿè©±ããã ãã§ãªããæè»ã§äœ¿ãããããã®ã§ãã ãã®ããŒã«ã¯ãæ¬çªç°å¢ã§ç¶ç¶çã«çºçãã倿°ã®å®éšãäœæ¥ãæŽæ°ã«å¯ŸåŠããå¿
èŠããããŸãã
éçºè
/管çè
ã®èгç¹ãããæ¬çªç°å¢ã§ãã°ãä¿®æ£ããããšããããããã€ã³ã¹ããŒã«ããããã»ã¹ã¯ã©ã®ããã«èŠããŸããïŒ ã³ãŒãå
ã®ãšã©ãŒãèŠã€ããŠä¿®æ£ããããã»ã¹ã¯çç¥ããŸãã
1.ã³ãŒããä¿®æ£ããããã«ãGITã«å¥ã®ãã©ã³ããäœæãããŸãã ããŒãžã§ã³ç®¡çã®äœ¿çšã¯ãå©äŸ¿æ§ã®ããã ãã§ãªãããã®åŸã®èª¿æ»ã®ããã«ãéåžžã«éèŠã§ãã
2. TeamCityãããããã«ãããã»ã¹ãèµ·åããŸãã æåã«ãæå®ããããã©ã³ããããããžã§ã¯ãã¢ã»ã³ããªãäœæãããæ¬¡ã«ãæ°ããã¢ã»ã³ããªãå®çšŒåç°å¢ã«ã€ã³ã¹ããŒã«ãããã¢ã»ã³ããªãšæ¯èŒãããŸãã ãããè¡ãããã«ãã¢ãŒã«ã€ããããã¹ãŠã®ãã¡ã€ã«ãæœåºããççŸãæ¯èŒãã倿ŽãŸãã¯è¿œå ããããã¡ã€ã«ã®ã¿ãéžæãããã«ãããŒã«ã®ãã©ã°ã€ã³ãäœæããŸããã ãã®å Žåãäž¡æ¹ã®ã¢ã»ã³ããªã®Javaã³ã³ãã€ã©ã®ããŒãžã§ã³ã¯åãã§ããå¿
èŠããããŸãã ã³ã³ãã€ã©ã®å¥ã®ããŒãžã§ã³ã§ã¯ç°ãªããã¡ã€ã«ãäœæãããã»ãŒãã¹ãŠã®ãããžã§ã¯ããã¡ã€ã«ããããã«å«ãŸããŸãã å¿
èŠãªãã¡ã€ã«ã®ã¿ãååŸãããå°ããªã¢ãŒã«ã€ããäœæããããšã¯éåžžã«éèŠã§ãã ããã«ããããããã倿°ã®ãµãŒããŒã«é
ä¿¡ããããã»ã¹ã倧å¹
ã«é«éåãããŸãã ãã«ãããã»ã¹ã¯ããããžã§ã¯ãã³ãŒãã®ãããã«é©ããŠããã ãã§ãªãããããžã§ã¯ãå
ã®ããããé©çšããã©ã€ãã©ãªã眮ãæããããšãã§ããŸãã 2ã€ã®ã¢ã»ã³ããªã®å
å®¹ãæ¯èŒãããšãã©ã€ãã©ãªïŒjarãã¡ã€ã«ïŒã«éããèŠã€ãããŸãã
3.ãã«ããæåããå Žåããããã¯ç¹å¥ãªãªããžããªã«éä¿¡ãããçµæãŠã£ã³ããŠã§ããŒïŒãŸãã¯ããã·ã¥ïŒãçºè¡ãããŸããããã¯ãããããäžæã«èå¥ããããã«å¿
èŠã§ãã

äœåºŠãäœåºŠãããããé©çšã§ããåãããŒãžã§ã³çªå·ã®ãã«ãã¯ããã·ã¥ãç°ãªããŸãã
4.次ã«ããã¹ãŠã®ã¢ã¯ãã£ããã£ãèšå®ãµãŒãã¹ã«è»¢éãããŸããéåžžã®UIã§ã¯ãã©ã®ãµãŒãã¹ãã©ã®ãã¹ããã©ã®ããŒãžã§ã³ã®ã¢ããªã±ãŒã·ã§ã³ã«ããããé©çšããããæå®ã§ããŸãã

ãã®ããã«è±å¯ãªãã©ã¡ãŒã¿ãŒã¯ãå¿
èŠãªã¬ãã«ã®èšå®ã®æè»æ§ãæäŸããŸããããã¯ãå€ãã®ãµãŒããŒã®å€§ããªåç©åã§éåžžã«éèŠã§ãã ãµãŒããŒã®äžéšã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã®ããŒãžã§ã³çªå·ãç°ãªã£ãŠããããã®ã³ãŒãã«ããããåœãŠãå¿
èŠã¯ãŸã£ãããªããšããŸãããã ãŸãã¯ãæ€èšŒã®ããã«ãHot Code Rreplaceãæåã«åäžã®ãµãŒããŒãŸãã¯ãµãŒããŒã®ã°ã«ãŒãã§èµ·åãããæ¬¡ã«ã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãŠã®ã€ã³ã¹ã¿ã³ã¹ã«åæ£ãããŸãã
5.æ§æã®å€æŽã«ãããéžæãããµãŒãã¹ã¯ãã€ã³ã¹ããŒã«ããå¿
èŠã®ãããããã®çš®é¡ãããŒãžã§ã³ãããã³æ€èšŒããã·ã¥ã«é¢ããæ
å ±ãåãåããŸãã èãã¯ããã¹ãŠã®ãµãŒãã¹ããããããã€ã³ã¹ããŒã«ãã³ãã³ããåä¿¡ããããããç¬ç«ããŠåäœãããšããããšã§ãã ç¬èªã«ããŒãžã§ã³ãæ¯èŒããããŒãžã§ã³ãäžèŽãããããã®ããã·ã¥ãæ¬ èœããŠãããç°ãªãå Žåã«ã®ã¿ããªããžããªãããããã¢ã»ã³ããªãåå¥ã«ããŠã³ããŒãããŸãã ããŠã³ããŒãããã»ã¹èªäœã¯HTTPãä»ããŠè¡ããããªããžããªã¢ãã¬ã¹ãããŠã³ããŒã詊è¡åæ°ãããã³å詊è¡éã®åŸ
æ©æéããã°ãã倿Žã§ããŸãã
6.åã¢ããªã±ãŒã·ã§ã³ã¯ãã¢ã»ã³ããªã®ããã·ã¥ãããŒã«ã«ã§æ€èšŒããå±éããŸãã åæã«ãåãã¡ã€ã«ã¯ãInstrumentation.getAllLoadedClassesïŒïŒã«ãã£ãŠè¿ãããé
åã®äžã§é
åå
ã«ååšãããã©ããããã§ãã¯ãããã¹ãŠã®æ°ããã¯ã©ã¹ãšãã¡ã€ã«ã¯æ°ããã¯ã©ã¹ãšäžæã¯ã©ã¹ãã¹ã«æžã蟌ãŸããŸãã redefineClassesã¡ãœããããã¹ã¹ã«ãŒããŸãã
7.ããã»ã¹å
šäœïŒã¢ããªã±ãŒã·ã§ã³ã®ãããé©çšã®å¿
èŠæ§ã«é¢ããã·ã°ãã«ã®å°çããã®ããŠã³ããŒããæ€èšŒãè§£åãããã³ã¢ããªã±ãŒã·ã§ã³ã¯ãã¢ããªã±ãŒã·ã§ã³ã®äžè¬ãã°ãšç¬èªã®ãã°ã®äž¡æ¹ã§è©³çްã«èšé²ããããããäžå¿
èŠãªãžã§ã¹ãã£ãŒãªãã§ããã»ã¹ãç£èŠã§ããŸãã
8.ãããã®æ£åžžãªé©çšåŸãããã»ã¹ã¯ããããã®ããã·ã¥ãå«ãç¹å¥ã«æ§æãããè¡ã远å ããããšã«ãããã¢ããªã±ãŒã·ã§ã³ã®ããŒãžã§ã³ãããããé©çšãããããŒãžã§ã³ã«å€æŽããããšã§çµäºããŸãã ãã¹ãã®ããŒãžã§ã³ãäºæããããŒãžã§ã³ã«å€æŽãããŠããªãå Žåã¯ããã®ãã¹ãã®ãããã³ãŒã眮æãã°ã«ç§»åããããã§èµ·ãã£ãããšã確èªããŸãã ããããéä¿¡ã®åé¡ã§ããå Žåã¯ããããã³ãã³ããå®å
šã«ç¹°ãè¿ãããšãã§ããç®çã®ãã¹ããå詊è¡ããŸãã
ã¢ããªã±ãŒã·ã§ã³ã«ããããé©çšã§ããªãå¯èœæ§ã®ããåé¡ã¯äœã§ããïŒ ãããã®ããªãã®æ°ãããããããã®äžã§ãç§ã¯æåŸã«ã€ã³ã¹ãã«ã¡ã³ããŒã·ã§ã³ã¯ã©ã¹ã®æ©èœã眮ããŸãã ãããŸã§ãredefineClassesã®å³å¯ãªæ¡ä»¶ãæºãããªãæ²ãã£ãã³ãŒãã¯ãã¢ããªã±ãŒã·ã§ã³ã«åœ±é¿ãäžããããšãªããåžžã«JVMã«ãã£ãŠãã©ãã·ã¥ãããŠããŸããã redefineClassesã¡ãœããã䜿çšãããšãJVMã¯ã¢ããªã±ãŒã·ã§ã³ãå®å
šã«åæ¢ããŸããããã®ããã»ã¹ã«ã¯äžç¬ããããŸãã æããªãããã§ã
æãå±éºãªç¬éã¯ã远å ã®åèšç·Žã«ãã£ãŠæ±ºå®ããããµãŒããŒãžã®ãããã®é
ä¿¡ã§ãã ãã ããåãã¬ã€ã圹ã«ç«ããªãå Žåã¯ãã³ãã³ããç¹°ãè¿ããŠããããåŒã³åºãããšãã§ããåãã¹ãã¯ããã»ã¹ãç¹°ãè¿ããŸãããå¿
èŠãªå Žåã«ã®ã¿ããããã€ã³ã¹ããŒã«ããŸãã ãããã以åã«ã€ã³ã¹ããŒã«ãããŠããªãããããã·ã¥ããŒã倿ŽãããŠããå Žåã
ä¿®æ£ããã°ã©ã ã1ã€ã®ãšã©ãŒãä¿®æ£ããæ°ãããšã©ãŒã远å ããå Žåã®å¥ã®æœåšçãªåé¡ã ãã®ãªã¹ã¯ãæå°éã«æããããã«ããŸããéãããæ°ã®ãµãŒããŒã«ããããã¢ããããŒããããã°ããã£ãŒãã確èªããŠçµæãç£èŠããŸãã ãã®åŸãä¿®æ£ãä»ã®ãã¹ãã«å±éããŸãã
ã¢ããªã±ãŒã·ã§ã³ãŸãã¯ãµãŒããŒãåèµ·åãããšã©ããªããŸããïŒ ããã¯ããã¹ãŠã®ã¯ã©ã¹ã¡ãŒãã¢ããªã±ãŒã·ã§ã³ã®ããžãã¯ã«æ¢ã«çµã¿èŸŒãŸããŠããŸããã¢ããªã±ãŒã·ã§ã³ã®æåã®1ã€ã¯HCRã¢ãžã¥ãŒã«ã§ãã ãŸããåæåäžã«ã¢ããªã±ãŒã·ã§ã³ã«ããããé©çšããå¿
èŠæ§ã«é¢ããæ
å ±ãéç¥ãããå Žåãããããæåã«é©çšãããŸãã
ãããŠãHot Code Replaceã®æ§æã«ã€ããŠå°ã説æããŸãã
- JavaAgentã JavaAgentã¯ã誰ããå¿ããå Žå ãããã¯ã¢ããªã±ãŒã·ã§ã³ã远å ãã©ã¡ãŒã¿ãŒã䜿çšããŠèµ·åãããšãã«JVMã«ãã£ãŠååŸããããç¹å¥ã«åœ¢æãããå¥åã®* .jarã¢ãŒã«ã€ãã§ããããšãã°ã-javaagentïŒ/path/to/lib/my-agent.jar Javaagent-ã®è¿œå æ©èœã®ããããããŠãã³ãŒã眮æããžãã¯ã䜿çšããããšãå¯èœã§ã ãšãŒãžã§ã³ãå
ã§java.lang.instrument.Instrumentationã¯ã©ã¹ã䜿çšã§ããŸãã ããããäœåãªã³ãŒãã§åœŒïŒãšãŒãžã§ã³ãïŒãè©°ãŸãããŸããã§ããã ãšãŒãžã§ã³ãã®æŽæ°ã¯éèŠãªã¿ã¹ã¯ã§ãããInstrumentationã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ããŠãŒãã£ãªãã£ã¯ã©ã¹ã®éçãã£ãŒã«ãã«ç§»åããã ãã§ãã ãããã£ãŠããã¹ãŠã®æäœã¯ãã¢ããªã±ãŒã·ã§ã³å
ã®ã©ãããã§ãéå§ã§ããŸãã
- æ§æãµãŒãã¹-ã¢ããªã±ãŒã·ã§ã³ã®æ§æãæ
åœãããããåã¢ããªã±ãŒã·ã§ã³ã§æåã«åæåãããŸãã Hot Code Replaceã®äž»ãªæ©èœãé ãããŠããã®ã¯ããã§ãã ã¢ããªã±ãŒã·ã§ã³ãèµ·åããããç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã®HCRæ§æã倿ŽãããšãããŒãžã§ã³ã®äºææ§ããã§ãã¯ãããäžèšã®ãã¹ãŠã®æäœãå®è¡ãããŸãã
- TeamCityããã³ãã«ãã¹ã¯ãªãã-ããããããç°¡åã«äœæãã倿ŽãŸãã¯è¿œå ãããã¯ã©ã¹ãšãªãœãŒã¹ã®ã¿ãä¿åããŸãã
ãã®ããŒã«ã®å©ç¹ã¯äœã§ããïŒ 1ã€ã¯ã補åã®é倧ãªãšã©ãŒãä¿®æ£ããé床ã§ãã ãã°ããããªãªãŒã¹ãåŸ
ã€ã®ã§ã¯ãªããååãã ãã ããšHCRã䜿çšãå§ããããšãããããŸãã æ¬¡ã¯ã¢ããªã±ãŒã·ã§ã³ã®é床ã§ãã ã¢ããªã±ãŒã·ã§ã³ã忢ããå¿
èŠã¯ãããŸãããJVMã¯äžç¬ã ãããªãŒãºãããã¹ãŠã®ãªããžã§ã¯ãã¯ãã®å Žæã«æ®ããåäœãç¶ããŸãã
ãããŠãåœç€Ÿã®éçºè
ã¯ããµãŒããŒã®æ°ãè² è·ã«é¢ä¿ãªããæ¬çªç°å¢ã§å³åº§ã«ç¬ç«ããŠãèªç±ã«ããããŠæ¥œããçããééããçŽããŸããã