Easy on the line

  Easy on the line - the growth of day 

  Posted on 2007-06-11 22:18 Sword spent reading (16) Comments (0) edit collections cited 

According name calling getName methods

  According name calling getName methods that is the question, I can see that there is actually a method is based on the name of name calling getName () This method. 
  And the realization of the methods used to achieve the judgement of the string of code as follows: 
  Public Object getOrderby () ( 
  If (ORDER_TITLE.equals (this.ordered)) ( 
  Return getTitle (); 
  ) Else if (ORDER_RENDERDATE.equals (this.ordered)) ( 
  Return getRenderDate (); 
  ) Else if (ORDER_CREATEDATE.equals (this.ordered)) ( 
  Return getCreateDate (); 
  ) Else if (ORDER_LASTMODIFIED.equals (this.ordered)) ( 
  Return getLastModified (); 
  Else () 
  Return getTitle (); 
  ) 
  ) 
  If so get after the new method means to increase this getOrderby () method judgement. 
  Therefore, I decided to transform reflection of this method, first of all, to define a method doGetMethod 
  Private Object doGetMethod (String methodName) throws Exception ( 
  Object result = null; 
  Object [] eo = new Object [] (); 
  String getMethodName = "get" + methodName.toLowerCase (); 
  Method methods = [] getClass (). GetMethods (); 
  For (int i = 0; i <methods.length; i + +) ( 
  Method method = methods [i]; 
  If (getMethodName.equals (method.getName (). ToLowerCase ())) ( 
  Result = method.invoke (this, eo); 
  ) 
  ) 
  Return result; 
  ) Here under methodName getMethodName combination, and then Method [] Method for this, then invoke calling this method invoke here to explain the parameters of this method is the first parameter is specified class includes methods, and the second parameter is specified methods need parameters. 
  Last modified the original getOrderBy 
  Public Object getOrderby () ( 
  Object obj = getTitle (); 
  Try ( 
  Obj = doGetMethod (getOrdered ()); 
  ) Catch (Exception e) ( 
  Return obj; 
  ) 
  Return obj; 
  ) Posted on 2007-04-12 15:36 rocket read (818) Comments (3) edit collections cited 
  Comments: # re: name calling getName methods 2007-04-12 17:36 | G_G 
 
Sofa 
 
Reply comments more 
 
# Re: name calling getName methods 2007-04-12 17:38 | popoer 
 
Good! Back more comments 
 
# Re: name calling getName methods 2007-04-12 19:57 | Liu Ganquan to make simple things complicated, and if it means using fixed if else is better, if necessary to change at any time, using different interface to achieve + reflection both more useful and more Reply Comments 

Jxl some summary 1

  Jxl some concluding a summary of some jxl 

  Xls file to the inside to write data when necessary to pay attention to the new one is the first to document xls 
  OutputStream os = new FileOutputStream ( "c: \ \ excel2.xls"); 

  End to build this document is a working document in time 
  Workbook.createWorkbook jxl.write.WritableWorkbook wwb = (new File (os)); 

  If this file already exists, then we can join in this document inside a sheet and to separate the data before; 
  Jxl.write.WritableSheet ws = wwb.createSheet ( "Test Sheet 1", 0); 
  In createSheet method, the parameters of the sheet in front of, and behind the sheet is to operate, 

  This document will be before the next write data to the inside 

  Pay attention to the time of data into the format 

  (1) add the font style 
  Jxl.write.WritableFont wf = new jxl.write.WritableFont (WritableFont.TIMES, 18, WritableFont.BOLD, true); 
  WritableFont () method, parameter: 
  This method can be considered a container, can be put to a lot of attributes: TIMES font size is, he is about 18 
  The second: BOLD is determine whether italics true choice at third italics: ARIAL 
  Fourth: UnderlineStyle.NO_UNDERLINE underlined fifth: jxl.format.Colour.RED font color is red. 

  Jxl.write.WritableCellFormat wcfF = new jxl.write.WritableCellFormat (wf); 

  Jxl.write.Label labelC new jxl.write.Label = (0, 0, "This is a Label cell," wcfF); 
  Ws.addCell (labelC); 
  In Label () method there are three parameters on behalf of a number of columns, 
  Second, representatives from several, 
  *** Section to write the content is the fourth option, the importation of this label inside the style sheet and then write the method addCell () content into sheet inside. 

  (2) Add objects with formatting the Number 
  Jxl.write.NumberFormat nf = new jxl.write.NumberFormat ("#.##"); 

  (3) Add Number object (3.1) show the number of the object data format 

  Jxl.write.NumberFormat nf = new jxl.write.NumberFormat ("#.##"); 
  Jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat (nf); 

  Jxl.write.Number labelNF new jxl.write.Number = (1, 1, 3.1415926, wcfN); 
  Ws.addCell (labelNF); 
  Number () method parameters: 
  The first two said that the location of the third input that the content of the importation 

  (4) Add a Boolean object 
  Jxl.write.Boolean labelB new jxl.write.Boolean = (0, 2, false); 
  Ws.addCell (labelB); 

  (5) Add DateTime object 
  Jxl.write.DateTime labelDT new jxl.write.DateTime = (0, 3, new java.util.Date ()); 
  Ws.addCell (labelDT); 
  DateTime () method that the parameters of the two previous position that the importation of third time that the current input 

  (6) Add the DateFormat with formatting object of this display the current time all the information, including hours of this day ever 
  Jxl.write.DateFormat df = new jxl.write.DateFormat ( "dd MM yyyy hh: mm: ss"); 
  Jxl.write.WritableCellFormat wcfDF new jxl.write.WritableCellFormat = (df); 
  Jxl.write.DateTime labelDTF new jxl.write.DateTime = (1, 3, new java.util.Date (), wcfDF); 
  Ws.addCell (labelDTF); 

  (7) Add a font color of the object Formatting 
  Jxl.write.WritableFont wfc = new jxl.write.WritableFont (WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED); 
  Jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat (wfc); 

  Import = "jxl.format .* 
  Jxl.write.WritableFont wfc = new jxl.write.WritableFont (WritableFont.ARIAL, 20, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN); 

  (8) a cell style 

  Jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat (wfc); 
  WcfFC.setBackGround (jxl.format.Colour.RED) / / set up cells for the color red 
  WcfFC new jxl.write.Label = (6,0, "i love china," wcfFC); 

  Jxl excel in the written document the methods used strange comparison, it can be said that jxl do not support amending excel document.    In the way it is every time they turn on the old excel document, and then create a document that can excel written copy of all changes in the copy are done.    Below is an example. 

  Posted on 2006-09-04 14:17 boddi reading (579) Comments (0) edit collections cited 

How effective the end of the project

  How effective the end of the project - a tax on the MIS system project summary of the experiences of 

  ????? "The Mythical Man-Month" at the beginning of the author Frederick P. Brooks Jr. Wrote: Prehistory, no other scene than the behemoth in the tar pits were dying and struggling even more shocking scenes .    God witnessed the dinosaurs, mammoths, saber-toothed tiger struggling in the tar.    They struggle more violent, more tight tangle of tar, there is no beast strong enough, or with sufficient skills to break free of restraints, they eventually sink to the bottom. 

  None Frederick P. Brooks Jr. Wrote the above text, we used an analogy of software projects, once started, similar to the kinds of animals struggling in the tar pits.    Excited at the beginning of the project, the excitement of the project for the rapid changes in the foreseeable future the end of the curse and despair. 
  None of the current domestic many software projects, this seems to have become a law, no matter how you do struggle, the project is not the end, and users can rely on competition patience, expected six-month project, so 18 months are common.    I also experienced the nightmare of as many projects, about how effective the end of a project to study the PMBOK, I would like to combine a recently completed tax MIS project to talk about his own views. 
  None in the PMBOK, for the stage of the project, divided into the following five sections: 
?

  None I will basically follow this five-part, described in this project is how to turn the end of the project. 
  ?????? 1, launched 
  None of the project company, we are long-time customers, customers and sales manager of a very close relationship, customers need to develop the software, we found a company directly, I, as technical director and sales manager with and , the exchange of software.    In the first contact, I feel for their own customers to be the needs of the software development is not very clear, but the client, project manager, is the director of the Center for the Inland Revenue Department's information for software development has a relatively rich experience, have taken part in the Golden Tax Project, and other large-scale software development.    This makes me feel so customers more easily exchange.    Indeed, this is also the actual situation, and after several exchanges, the project basically decided, I was appointed the company's project manager of the project for the development of the project. 
  None in this process, I would like to as a project manager, one must be clear thinking, which is the goal of the project management is to realize the objectives of the project, the end of the project.    This concept should always run through project management, therefore, in the initial exchanges and users, we will have to consider how to end the project, it needs to achieve the goal of what users can only recognition of the project's overall cost of the company for the project Is there any limitation on the development cycle, the risks of the project as a project team can withstand such. 
  None specific to this project, at the beginning, I found that the biggest risk in the project with the users feel that this project is very simple, but the demand is still rather vague, of course, this is the most common item, I admit that The project compared with the Golden Tax Project is very simple (a Golden Tax Project complex projects do not:), but if you take this kind of attitude will inevitably arise when the mad rush project development period, the late Bug everywhere, needs to change Instead, many users complain, a company sales incentives, with a research and development staff of the surgery.    Therefore, I would like to how to find a suitable opportunity to project development, as well as the difficulty of the concept of project management and communication between users. 
  ?????? I was distressed when users of the technical information they hope to conduct a staff training to keep abreast of the projects in the Java technology.    I know that the opportunity has come, and during the 10-day technical courses arrangements, I managed to find some time on a one-day project management, curriculum arrangements to users, the user, I found a little secret: specifically made a phone call to ask me on the day of project management whether it is necessary to seize this opportunity, I先给Information Center Director speakers stressing the importance of project management, as well as the difficulty of this software, the risk cycle, so that the user agreed to the request.    At the beginning of the project, access to the client, project manager of the recognition is very necessary, if your ideas and practices so that customers at the beginning of the project managers recognized that it is difficult, I think, to do with the difficulty of the project will be very large. 
  None followed by the signing of the contract and a 10-day training in, I will PMBOK concepts of project management throughout the entire training, in particular is the last item on the management of, basically achieve the expected effect, allows customers recognize that software development is not in the preparation process, which involves all aspects of the project was not a success, with the participation and it is very difficult to succeed.    The end of the project, I also made a director of the Center for Information and repeated communications, the two sides basic mutual understanding of each other's needs and ideas.    This was the smooth progress of the project has laid a good foundation. 
  None of the project through the start, I discovered that, if conditions at the time of the customer to conduct a training very conducive to the smooth progress of the project.    In the training process, and customers become friends, and their project team and the development of methods for customers seriously exchanges to allow customers recognized development team, and the training time buffer, on the one hand, can organize other technical staff for the project possible technical difficulties breakthroughs, on the other hand, can exchange programs and private demand, the demand for this kind of informal exchange often than formal exchange more easily demand that the original intention of the project initiated by a customer and client to achieve. 

  None 2, plans 
  None in the planning phase, at the beginning of the start-up phase should demand to know the general outline of the plan, with clearly defined project completion date, the plan to be submitted to the users on the one hand, on the other hand, informed the project Group members and project management company or company leaders.    Of course, here the clear end date of the general project under all circumstances and projects a far cry from the real end date (so far I have not encountered before exceptional circumstances), this does not matter, because the demand after the end of investigation, and an additional refinement project, redefined the end of the project period.    But no matter how clear, then the end of the project on schedule often from customers, companies, the pressure to make the plan always an ideal situation in accordance with the arrangements, for example, the following is my demand after the project plan: 

  ??????? This project is to the client, and the leadership of the company made under the dual pressure of that time, project managers must remain sober-minded, regardless of the plan is how much time the end of the project, and my heart must be clear actually completed and the approximate timing of the planned time gap, and that gap client whether they can bear.    Thus, in the course of the project, in accordance with the plan to gradually adjust gradually to customers and the company reported adjusted reasons, the easier to achieve both customers and companies basically satisfied with the outcome.    If the gap is too wide, the plan will argue, of course, this is a more difficult, but compared to the ultimate customer and the company was double censure, it is quite worthwhile. 
  The above plan is submitted, I estimate that the final time around the end of five weeks later than planned around major repair of the system is missing, that is, after the commencement of trial operation, users will put forward many views, two weeks time should be completed or not, However, if directly in the plan put forward seven weeks time, users absolutely unacceptable, the company also can not accept, the project may be a standstill, under pressure, I did two weeks of repair missing, then how should we do when the time comes ?    I usually practice is in the best repair for a long time after missing, first of all, the basic guarantee of trial operation on schedule, which, I believe most project teams can guarantee, and then take more in the development of on-line version of the way, as far as possible allows users to propose amendments as soon as possible, so as to secure as soon as possible revision, third, after the commencement of trial operation, user comments, timely adjustment project and to notify users, allowing users to understand when his views were adopted after the end of the project time What was postponed, to the user a certain degree of pressure can reduce the views of the early closure of projects.    Also, is possible, as far as possible, the actual estimate of the time and their own leaders in charge of communication, access to his support to ensure worry-free (this is an important point, but it depends on the relationship between you and the leadership of the:). 
  None after that, I originally estimated basic right, the end of the project some time later than the planned four weeks time around, because of the development of software for users familiar with and, if encountered relatively trouble customers, dating to the time late, but as long as there are adequate prior estimates, it would not rush. 

  None 3, the Executive 
  None relatively smooth implementation process, and customers have maintained a good relationship, the customer received the strong support of刁钻basically no problem.    In this process, a part of the beginning, we have developed in this process, we have developed some modules, as version 0.1, to the scene to carry out the installation to the user. 
  To do so, I think there are several advantages, first of all, allows users to feel the project has been ongoing, and users and does not undermine the relationship of trust and, secondly, as to understand the actual situation at the scene, if found, timely adjustment to the development direction or User adjustments site.    Again, can be part of the module allows users to propose amendments as soon as possible, in the development of the remaining modules, can be part of this revision, and the views through to other modules to reduce the time behind the revision. 
  None developed largely after the end, we have entered the scene to users for installation debugging, and then for system modifications, this is the most difficult time, at this point in time, users, companies, and project teams can easily tired, tired, anger, despair, and to all sins Doudui project manager to the head.    Therefore, at this time as a project manager in order to maintain a high degree of vigilance, we must have integrity of the project log, recording the daily progress of the users must be maintained and good communication with the project manager, to keep the problems and progress reports, and companies, to help them understand The project team every day in what to do and why the end of time would be a push再推; project team members must observe the situation, to prevent fatigue and loss of a staff; must always remind ourselves that the goal of the project is the end of the project, all of on the end of the project must be carried out. 
  None in this process, we project team has basically boil over, in my end of the expected time of the project, although there are still many areas not satisfactory, but, after all, as the project ended, everyone reduce pressure can be better sum up experience. 

  ?????? 4, control 
  None of the items in the process, there will be a wide range did not expect the problem encountered such contingencies, project managers need timely resolved. 
  None in this item in the process of development entered the most crucial moment, the technical backbone of the project team made a sudden departure, which I had not thought is prepared, if he really leave, it will be of project causing great trouble.    This time, and I had a lengthy communication to understand the reasons for his departure, and if we can retain, as far as possible to retain. 
  None After the exchange, he found to resign was based on three reasons are: First, the company's long-term dissatisfaction with the company in a longer will be a variety of dissatisfaction with the company, this is for them, despite my increase salaries and improve jobs, but it is very difficult for the company to his dissatisfaction been fundamentally resolved, and the second is the pressure of specific lives, in our treatment of the salaries of two cities very difficult to solve, such as marriage purchases of specific pressure, and he hopes to to Beijing this treatment relatively good salary, which is what we are now facing the loss of a major challenge, but this problem in the short term I am afraid that no better way, and the third is the longing for the outside world, in a two cities spent time long, so close to Beijing for the National Information Center will have longing, hope, technology, ideology, and other areas in Beijing can be raised. 
  None of these problems are widespread problem, I can not solve them altogether for him, but consider for the project, through persuasion, because we usually very good relations, he agreed to stay about a month's time, he was responsible for solving part of the technical issues, while making handover work.    This project, on the lifting of the crisis, because there are a month's time, can make good arrangements for all. 
  None for a crisis like this, I think, as a project manager, first, and usually it is necessary to pay attention to the relationship between the team members, when a variety of situations, even with out, and can help themselves to tide over the crisis; 2 For many problems, we must understand that in peacetime team members on the need, we can help resolve, to resolve, and will not wait until the time in question, it can not be resolved, and let you know the difficulties and specific environmental constraints, Do not let you guys take the company; Third, we need to bear in mind is the core of team-building team members of the personal development, to give each member of the growth of space, including technical, salaries, jobs, and so on, otherwise, once members of the team reached the pinnacle of development, it will see no future, I am afraid that separation is inevitable choice. 
??????

  None 5, ending 
  None the most difficult stage of completion?    Progress!    This time, facing the end of the project, all of the progress will be very concerned about.    How to try to persuade users to the end of the endless changes, the smooth conclusion of the project, each project manager must face. 
  None in this project, because a great deal of work early, in the run-ending, we have prepared a comprehensive document, the solution of the current Bug, and a commitment to the future, the two sides are relatively satisfied with the and smoothly signed a preliminary post-mortem report, users are made to pay the project, the end of the item. 
  None So, I think, does not depend on the successful completion stage of completion of work, but to work through completion of the project has always been, if fully prepared early, ending when the biggest conflict, progress on the project will not become Manager biggest problem, on the contrary, if the completion stage began to consider how to end the project, I am afraid that the end of the project will be put off indefinitely. 

  None of this project is in addition to routine maintenance and simple modifications, a lot of work has not, although the successful conclusion of the project, there are many incidental factors, such as the user's active support (which is rare in other projects to the general user-Baibandiaonan), but I think he still has some common characteristics of small and medium-sized projects, as a project manager, I propose to share with you our objective is to sum up experience, and can jump out of the tar pit project, smooth to the end of each item. 

  Posted on 2006-11-24 18:04 GuanHui Reading (77) Comments (0) edit their collections quoted Category: Other 

Wing component-window tooltip

  Swing components-windows tooltip 

  The effect of windows applications 

  Do swing the results obtained: 

  Cling to the more complex code out in the swing components-box ToolTip conversation on the basis of doing them. 

  Posted on 2007-03-16 17:50 azure reading (1264) Comments (4) Edit collections cited 

MD5 Algorithm JAVA_BEAN

  MD5 Algorithm JAVA_BEAN 

  Package org.waityou.news.util; 

  Import java.lang.reflect .*; 

  /************************************************* SUMMARY 
  * Md5 class implements RSA Data Security, Inc. Submitted to the IETF RFC1321 the MD5 message-digest algorithm. 
  ************************************************** ****************************/ 

  (Public class MD5 
  / * 
  * Below these S11-S44 is actually a 4 x 4 matrix, in the realization of the original C # define is used to achieve, and here they realize become static 
  * The final is that the read-only, cut in the same space, a process shared among multiple Instance 
  * / 
  Static final int S11 = 7; 

  Static final int S12 = 12; 

  Static final int S13 = 17; 

  Static final int S14 = 22; 

  Static final int S21 = 5; 

  Static final int S22 = 9; 

  Static final int S23 = 14; 

  Static final int S24 = 20; 

  Static final int S31 = 4; 

  Static final int S32 = 11; 

  Static final int S33 = 16; 

  Static final int S34 = 23; 

  Static final int S41 = 6; 

  Static final int S42 = 10; 

  Static final int S43 = 15; 

  Static final int S44 = 21; 

  Static final byte [] = (PADDING -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0); 

  / * 
  * Below the three members of MD5 is used in the computation of the three core data, in the realization of the original C, which is defined by the structure of the MD5_CTX 
*
  * / 
  Private long state [] = new long [4]; / / state (ABCD) 

  Private long [] = new long count [2] / / number of bits, modulo 2 ^ 64 (lsb 

  / / First) 

  Private byte buffer [] = new byte [64]; / / input buffer 

  / * 
  * DigestHexStr MD5 is the only member of the public, is the latest of the results of a 16-band ASCII said. 
  * / 
  Public String digestHexStr; 

  / * 
  * Digest, is the latest of the results of a 2-band internal said that the 128-bit MD5 value. 
  * / 
  Digest private byte [] = new byte [16]; 

  / * 
  * GetMD5ofStr category is the most important public MD5, you want to import parameter is a string transform MD5 
  * End transformation is the return of the results of this result is achieved digestHexStr from members of the public. 
  * / 
  Public String getMD5ofStr (String inbuf) ( 
  Md5Init (); 
  Md5Update (inbuf.getBytes (), inbuf.length ()); 
  Md5Final (); 
  DigestHexStr = ""; 
  For (int i = 0; i <16; i + +) ( 
  DigestHexStr + = byteHEX (digest [i]); 
  ) 
  Return digestHexStr; 

  ) 

  / / This is the standard MD5 this class constructor is JavaBean call for a public parameters of the structure and did not function 
  Public MD5 () ( 
  Md5Init (); 

  Return; 
  ) 

  / * Initialize md5Init is a function of the core initialization variables into standard magic number * / 
  Private void md5Init () ( 
  Count [0] = 0L; 
  Count [1] = 0L; 
  / / / * Load magic initialization constants. 

  State [0] = 0×67452301L; 
  State [1] = 0xefcdab89L; 
  State [2] = 0×98badcfeL; 
  State [3] = 0×10325476L; 

  Return; 
  ) 

  / * 
  * F, G, H and I are four basic MD5 function, in the original C MD5 realize, because they are 
  * Simple-bit computing, the efficiency may be considered for the achievement of their Acer has become the java, we put them into private achieve, maintain the original name of the C. 
  * / 

  Private long F (long x, long y, long z) ( 
  Return (x & y) | ((~ x) & z); 

  ) 

  Private long G (long x, long y, long z) ( 
  Return (x & z) | (y & (~ z)); 

  ) 

  Private long H (long x, long y, long z) ( 
  Return x ^ y ^ z; 
  ) 

  Private long I (long x, long y, long z) ( 
  Return y ^ (x | (~ z)); 
  ) 

  / * 
  * FF, GG, HH, and II will be called F, G, H, I conducted closer to transform FF, GG, HH, and II transformations for 
  * Rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent 
  * Recomputation. 
  * / 

  Private long FF (long a, long b, long c, long d, long x, long s, long ac) ( 
  F = a + (b, c, d) + x + ac; 
  A = ((int) a <<s) | ((int) a>>> (32 - s)); 
  = A + b; 
  Return a; 
  ) 

  Private long GG (long a, long b, long c, long d, long x, long s, long ac) ( 
  G = a + (b, c, d) + x + ac; 
  A = ((int) a <<s) | ((int) a>>> (32 - s)); 
  = A + b; 
  Return a; 
  ) 

  Private long HH (long a, long b, long c, long d, long x, long s, long ac) ( 
  H = a + (b, c, d) + x + ac; 
  A = ((int) a <<s) | ((int) a>>> (32 - s)); 
  = A + b; 
  Return a; 
  ) 

  Private long II (long a, long b, long c, long d, long x, long s, long ac) ( 
  I = a + (b, c, d) + x + ac; 
  A = ((int) a <<s) | ((int) a>>> (32 - s)); 
  = A + b; 
  Return a; 
  ) 

  / * 
  * MD5 is the main md5Update calculation process, inbuf is to transform strings of bytes, inputlen is the length of this 
  * Function from getMD5ofStr call, call call md5init needed before, it's designed private 
  * / 
  Private void md5Update (inbuf byte [], int inputLen) ( 

  Int i, index, partLen; 
  Byte [] = new byte block [64]; 
  Index = (int) (count [0]>>> 3) & 0×3F; 
  / / / * Update number of bits * / 
  If ((count + [0] = (inputLen <<3)) <(inputLen <<3)) 
  Count [1] + +; 
  Count [1] + = (inputLen>>> 29); 

  PartLen = 64 - index; 

  / / Transform as many times as possible. 
  If (inputLen> = partLen) ( 
  Md5Memcpy (buffer, inbuf, index, 0, partLen); 
  Md5Transform (buffer); 

  For (i = partLen; i + 63 <inputLen; i + = 64) ( 

  Md5Memcpy (block, inbuf, 0, i, 64); 
  Md5Transform (block); 
  ) 
  Index = 0; 

  ) Else 

  I = 0; 

  / / / * * Buffer remaining input / 
  Md5Memcpy (buffer, inbuf, index, i, inputLen - i); 

  ) 

  / * 
  * Md5Final organize and fill in output 
  * / 
  Private void md5Final () ( 
  Byte [] bits = new byte [8]; 
  Int index, padLen; 

  / / / * Save number of bits * / 
  Encode (bits, count, 8); 

  / / / * Pad out to 56 mod 64. 
  Index = (int) (count [0]>>> 3) & 0×3f; 
  PadLen = (index <56) - (56 - index): (120 - index); 
  Md5Update (PADDING, padLen); 

  / / / * Append length (before padding) * / 
  Md5Update (bits, 8); 

  / / / * Store state in digest * / 
  Encode (digest, state, 16); 

  ) 

  / * 
  * Md5Memcpy the internal use of a byte array block copy function, input from the beginning of the len inpos length 
  * Bytes copied to the output location of the beginning of outpos 
  * / 

  Private void md5Memcpy (byte [] output, input byte [], int outpos, int inpos, 
  Int len) ( 
  Int i; 

  For (i = 0; i <len; i + +) 
  Output [outpos + i] = input [inpos + i]; 
  ) 

  / * 
  * Md5Transform is MD5 core transformation process, md5Update call, block is the original byte block 
  * / 
  Private void md5Transform (byte block []) ( 
  Long a state [0] = b = state [1], c = state [2], d = state [3]; 
  Long x = [] [16] new long; 

  Decode (x, block, 64); 

  / * Round 1 * / 
  A = FF (a, b, c, d, x [0], S11, 0xd76aa478L) / * 1 * / 
  D = FF (d, a, b, c, x [1], S12, 0xe8c7b756L) / * 2 * / 
  C = FF (c, d, a, b, x [2], S13, 0×242070dbL) / * 3 * / 
  B = FF (b, c, d, a, x [3], S14, 0xc1bdceeeL) / * 4 * / 
  A = FF (a, b, c, d, x [4], S11, 0xf57c0fafL) / * 5 * / 
  D = FF (d, a, b, c, x [5], S12, 0×4787c62aL) / * 6 * / 
  C = FF (c, d, a, b, x [6], S13, 0xa8304613L) / * * / 
  B = FF (b, c, d, a, x [7], S14, 0xfd469501L) / * 8 * / 
  A = FF (a, b, c, d, x [8], S11, 0×698098d8L) / * 9 * / 
  D = FF (d, a, b, c, x [9], S12, 0×8b44f7afL) / * 10 * / 
  C = FF (c, d, a, b, x [10], S13, 0xffff5bb1L) / * 11 * / 
  B = FF (b, c, d, a, x [11], S14, 0×895cd7beL) / * 12 * / 
  A = FF (a, b, c, d, x [12], S11, 0×6b901122L) / * 13 * / 
  D = FF (d, a, b, c, x [13], S12, 0xfd987193L) / * 14 * / 
  C = FF (c, d, a, b, x [14], S13, 0xa679438eL) / * 15 * / 
  B = FF (b, c, d, a, x [15], S14, 0×49b40821L) / * 16 * / 

  / * Round 2 * / 
  A = GG (a, b, c, d, x [1], S21, 0xf61e2562L) / * 17 * / 
  D = GG (d, a, b, c, x [6], S22, 0xc040b340L) / * 18 * / 
  C = GG (c, d, a, b, x [11], S23, 0×265e5a51L) / * 19 * / 
  B = GG (b, c, d, a, x [0], S24, 0xe9b6c7aaL) / * 20 * / 
  A = GG (a, b, c, d, x [5], S21, 0xd62f105dL) / * 21 * / 
  D = GG (d, a, b, c, x [10], S22, 0×2441453L) / * 22 * / 
  C = GG (c, d, a, b, x [15], S23, 0xd8a1e681L) / * 23 * / 
  B = GG (b, c, d, a, x [4], S24, 0xe7d3fbc8L) / * 24 * / 
  A = GG (a, b, c, d, x [9], S21, 0×21e1cde6L) / * 25 * / 
  D = GG (d, a, b, c, x [14], S22, 0xc33707d6L) / * 26 * / 
  C = GG (c, d, a, b, x [3], S23, 0xf4d50d87L) / * 27 * / 
  B = GG (b, c, d, a, x [8], S24, 0×455a14edL) / * 28 * / 
  A = GG (a, b, c, d, x [13], S21, 0xa9e3e905L) / * 29 * / 
  D = GG (d, a, b, c, x [2], S22, 0xfcefa3f8L) / * 30 * / 
  C = GG (c, d, a, b, x [7], S23, 0×676f02d9L) / * 31 * / 
  B = GG (b, c, d, a, x [12], S24, 0×8d2a4c8aL) / * 32 * / 

  / * Round 3 * / 
  A = HH (a, b, c, d, x [5], S31, 0xfffa3942L) / * 33 * / 
  D = HH (d, a, b, c, x [8], S32, 0×8771f681L) / * 34 * / 
  C = HH (c, d, a, b, x [11], S33, 0×6d9d6122L) / * 35 * / 
  B = HH (b, c, d, a, x [14], S34, 0xfde5380cL) / * 36 * / 
  A = HH (a, b, c, d, x [1], S31, 0xa4beea44L) / * 37 * / 
  D = HH (d, a, b, c, x [4], S32, 0×4bdecfa9L) / * 38 * / 
  C = HH (c, d, a, b, x [7], S33, 0xf6bb4b60L) / * 39 * / 
  B = HH (b, c, d, a, x [10], S34, 0xbebfbc70L) / * 40 * / 
  A = HH (a, b, c, d, x [13], S31, 0×289b7ec6L) / * 41 * / 
  D = HH (d, a, b, c, x [0], S32, 0xeaa127faL) / * 42 * / 
  C = HH (c, d, a, b, x [3], S33, 0xd4ef3085L) / * 43 * / 
  B = HH (b, c, d, a, x [6], S34, 0×4881d05L) / * 44 * / 
  A = HH (a, b, c, d, x [9], S31, 0xd9d4d039L) / * 45 * / 
  D = HH (d, a, b, c, x [12], S32, 0xe6db99e5L) / * 46 * / 
  C = HH (c, d, a, b, x [15], S33, 0×1fa27cf8L) / * 47 * / 
  B = HH (b, c, d, a, x [2], S34, 0xc4ac5665L) / * 48 * / 

  / * Round 4 * / 
  A = II (a, b, c, d, x [0], S41, 0xf4292244L) / * 49 * / 
  D = II (d, a, b, c, x [7], S42, 0×432aff97L) / * 50 * / 
  C = II (c, d, a, b, x [14], S43, 0xab9423a7L) / * 51 * / 
  B = II (b, c, d, a, x [5], S44, 0xfc93a039L) / * 52 * / 
  A = II (a, b, c, d, x [12], S41, 0×655b59c3L) / * 53 * / 
  D = II (d, a, b, c, x [3], S42, 0×8f0ccc92L) / * 54 * / 
  C = II (c, d, a, b, x [10], S43, 0xffeff47dL) / * 55 * / 
  B = II (b, c, d, a, x [1], S44, 0×85845dd1L) / * 56 * / 
  A = II (a, b, c, d, x [8], S41, 0×6fa87e4fL) / * 57 * / 
  D = II (d, a, b, c, x [15], S42, 0xfe2ce6e0L) / * 58 * / 
  C = II (c, d, a, b, x [6], S43, 0xa3014314L) / * 59 * / 
  B = II (b, c, d, a, x [13], S44, 0×4e0811a1L) / * 60 * / 
  A = II (a, b, c, d, x [4], S41, 0xf7537e82L) / * 61 * / 
  D = II (d, a, b, c, x [11], S42, 0xbd3af235L) / * 62 * / 
  C = II (c, d, a, b, x [2], S43, 0×2ad7d2bbL) / * 63 * / 
  B = II (b, c, d, a, x [9], S44, 0xeb86d391L) / * 64 * / 

  State [0] = a +; 
  State [1] + = b; 
  State [2] + = c; 
  State [3] + = d; 

  ) 

  / * 
  * Encode the long array in order demolition of a byte array, because of the long java type 64-bit, 32-bit low only demolished to accommodate the use of realization of the original C 
  * / 
  Private void Encode (byte [] output, long input [], int len) ( 
  Int i, j; 

  For (i = 0, j = 0, j <len; i + +, j + = 4) ( 
  Output [j] = (byte) (input [i] & 0xffL); 
  Output [j + 1] = (byte) ((input [i]>>> 8) & 0xffL); 
  Output [j + 2] = (byte) ((input [i]>>> 16) & 0xffL); 
  Output [j + 3] = (byte) ((input [i]>>> 24) & 0xffL); 
  ) 
  ) 

  / * 
  * Decode the byte array in order of a long array, because of the long type java is 64 bit, 
  * Only low of 32 bit, 32-bit high-cleared to adapt to the use of achieving the original C 
  * / 
  Private void Decode (long [] output, input byte [], int len) ( 
  Int i, j; 

  For (i = 0, j = 0, j <len; i + +, j + = 4) 
  Output [i] = b2iu (input [j]) | (b2iu (input [j + 1]) <<8) 
  | (B2iu (input [j + 2]) <<16) | (b2iu (input [j + 3]) <<24); 

  Return; 
  ) 

  / * 
  * B2iu is, I wrote a byte to not consider positive and negative, in accordance with the principles of the "l-bit" procedures, not because of java unsigned computing 
  * / 
  Public static long b2iu (byte b) ( 
  Return b <0? B & 0×7F + 128: b; 
  ) 

  / * 
  * ByteHEX (), used to a few types of byte hexadecimal convert the ASCII representation, 
  * Because the java byte in the toString unable to achieve this, we have not in the C language sprintf (outbuf, "% 02X", ib) 
  * / 
  Public static String byteHEX (byte ib) ( 
  Digit char [] = ('0 ','1','2 ','3','4 'and'5','6 ','7','8 ','9', 'A', 
  'B', 'C', 'D', 'E', 'F'); 
  Ob char [] = new char [2]; 
  Ob Digit [0] = [(ib>>> 4) & 0X0F]; 
  Ob Digit [1] = [ib & 0X0F]; 
  String s = new String (ob); 
  Return s; 
  ) 

  Public static void main (String args []) ( 

  MD5 m = new MD5 (); 
  If (Array.getLength (args) == 0) (file: / / If there are no parameters, the implementation of standards Test Suite 

  System.out.println ( "MD5 Test suite:"); 
  System.out.println ( "MD5 (\" 850817 \ "):" + m.getMD5ofStr ( "850817")); 
  System.out.println ( "MD5 (\" \ "):" + m.getMD5ofStr ("")); 
  System.out.println ( "MD5 (\" a \ "):" + m.getMD5ofStr ( "a")); 
  System.out.println ( "MD5 (\" abc \ "):" + m.getMD5ofStr ( "abc")); 
  System.out.println ( "MD5 (\" message digest \ "):" 
  + M.getMD5ofStr ( "message digest")); 
  System.out.println ( "MD5 (\" abcdefghijklmnopqrstuvwxyz \ "):" 
  + M.getMD5ofStr ( "abcdefghijklmnopqrstuvwxyz")); 
System.out
  . Println ( "MD5 (\" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 \ "):" 
  + M 
  . GetMD5ofStr ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")); 
  ) Else 
System.out
  . Println ( "MD5 (" + + args [0] ") =" + m.getMD5ofStr (args [0])); 

  ) 

  ) 

  Posted on 2005-12-31 16:28 ZengChang Reading (62) Comments (1) edit their collections quoted Category: Learning Notes 

Displayed on the pages in HTML code JAVA CRIPT

  Displayed on the pages in HTML code JAVA SCRIPT 

  <script Defer> 
  Function _show (str) ( 
  ? Var w = window.open ('',''); 
  ? Var d = w.document; 
  ? D.open (); 
  ? Str = str.replace (/=(?!")(.*?)(?!")( | ") / g," = \ "$ 1 \" $ 2 "); 
  ? Str = str.replace (/(<)(.*?)(>)/ g, "<span style='color:red;'> <$ 2> </ span> <br />"); 
  ? Str.replace str = (/ \ r / g, "<br /> \ n"); 
  ? D.write (str); 
  ?) 
  </ Script> 
<html>
<body>
<form>
  <input Type="button" value="SHOW" onClick="_show(document.documentElement.innerHTML)" /> 
  </ Form> 
  </ Body> 
  </ Html> 

  Middle spent the regular expression 

  Posted on 2006-06-01 17:00 ZengChang Reading (68) Comments (0) quoted edit collections for the category: Learning Notes 

Basic concept

  Basic concept of the basic concepts: 

  Computer has been able to deal with numerical, text, voice, images and other information, in fact, the information is converted into computer can identify the form of address.    Current computer processing all information with "0" and "1" combination of the two figures binary symbols to express.    However, as long binary said that the figures for some of the questions, not statements intuitive, so have the octal, and hexadecimal. 

  Binary features: 

  1) there are two figures: 0,1 
  2) a binary computing时逢 

  Octal features: 
  1) eight figures: 0,1,2,3,4,5,6,7 
  2) computing into an eight时逢 

  Hexadecimal features: 
  1) 16 figures: 0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F 
  2) into a computing时逢16 
  Note: A, B, C, D, E, F, respectively, said that 10 to 15.    Not case-sensitive. 
  Posted on 2007-04-27 17:05 WÇ’ dynamic reading with the heart (69) Comments (1) edit collections cited 
  FeedBack: # re: basic concepts 2007-04-28 11:23 | My heart still ah, see.    ^ _ ^, In a move.    Reply comments more 

Java RMI Tutorial

  Java RMI Tutorial 

  Getting Started Guide Remote Method Invocation (Java RMI Tutorial) 

  Java R MI Tutorial 

  Remote Method Invocation Getting Started 

  Stephen Suen 

  Copyright © 2005 Stephen Suen All rights reserved. 

  Java Remote Method Invocation (Remote Method Invocation, RMI) made a run in the Java Virtual Machine (Java Virtual Machine, JVM) running another object can call other objects on the JVM method, which provides a procedure for remote communication between the channels.    RMI is distributed J2EE many of the foundation, for example, RMI-IIOP and EJB.    In this paper, RMI is a Getting Started Guide aims to help readers rapid establishment of a perceptual knowledge of Java RMI, for a deeper level of learning.    In fact, if you know RMI is aimed at better understanding and learning EJB, then this article could not have been better.    Adoption of this understanding of the RMI with the knowledge and skills should be sufficient serve this objective. 

  The latest version of this paper will be posted on the Web site programmer cafe (construction).    Welcome to subscribe to our mailing list to receive the formal release on the paper and update information. 

  By ensuring integrity, and retain all copyright statement (including the above link) on the premise can be reproduced in any medium - this notice is preserved. 


  Contents 
  1. Introduction 
  2. Distributed Object 
  3. RMI framework 
  4. RMI Object Service 
  5. Combat RMI 
  6. Definition Remote Interface 
  7. Remote Interface 
  8. Boot 
  9. Client program 
  10. Compiled examples of procedures 
  11. Operating procedures Example 
  12. Other information 
  13. BRIEF 

  1. Introduction 

   We know that Remote Procedure Call (Remote Procedure Call, RPC) can be used in a process called another process (probably in another remote console) in the process, which provides a capacity of the distribution process.      Java RMI in the RPC and on the basis of a step forward, that is, to provide communications between distributed objects, and allows us to access remote objects in the process (known as the remote object) used (as quoted remote), then Call remote object through the use of the method, as if the object with your client code running in the same process as local.      RMI used the term "method" (Method) stressed that progress, that is distributed on the basis of full support for object-oriented features.  

  RMI is not supported in Java Remote Method Invocation the only choice.    In the RMI from developed on the basis of the RMI-IIOP (Java Remote Method Invocation over the Internet Inter-ORB Protocol), not only inherited the bulk of RMI advantages, and can be compatible with CORBA.    EJB J2EE and all require the use of RMI-IIOP instead of RMI.    Nevertheless, understanding RMI will greatly contribute to the understanding of RMI-IIOP.    Therefore, even if your interest in the RMI-IIOP or EJB, I believe this will be helpful to you.    Also, if you are interested in on the API, it can tell you that the use of RMI java.rmi packets, and RMI-IIOP is used both java.rmi javax.rmi also use the expansion pack. 

  In this paper, the content will then only for Java RMI. 

  2. Distributed Object 

  RMI in the study, we need to understand some basic knowledge.    First need to understand the so-called Distributed Objects (Distributed Object).    Distributed object is an object can be called by the remote system.    For Java, which can be targeted not only in the same virtual machine, other procedures (Client) call, they can also be other virtual machine running on the client calls, and even through the network by other remote host on the client calls . 

  Below the icon of the process is how the customer calls the Distributed Object: 

  From Figure, we can see that the distributed object to be called the process is this: 

  1.   , A procedure known as Stub call (sometimes translated as cookies, in order not to have ambiguity, we will use the English form), the client agent targets.    The agent responsible for client objects hide the details of network communications.    Stub know how to network socket (Socket) sent calls, including calls to be converted to the appropriate parameters to the form of transmission. 

  2.   Stub call through the network will be transmitted to the server, which is the end of a distributed object known as the Skeleton proxy object.    Similarly, the agent responsible for the Distributed Object object hidden network communications details.    Skeleton know how from the network socket (Socket) to accept the call, including how to call from the network transmission parameters converted to the form of Java form. 

  3.   Skeleton call will be transmitted to the Distributed Object.    Distributed Object implementation of the corresponding call, will be followed by the return value passed to the Skeleton and then transmitted to the Stub, and ultimately back to the client. 

  This scene is based on a fundamental principle, that is, and the definition of the specific acts to achieve phase separation.    As shown, the client agent and the Distributed Object Object Stub achieved the same interface called Remote Interface (Remote Interface).    It is the definition of the interface, and distributed object itself provide specific implementations.    The Java RMI, we Interface (interface) definition, use category (class) is defined to achieve. 

  3. RMI framework 

  RMI from the bottom of the three-tier structure composed of: 

  •   First, Stub / Skeleton layer.    The layer procedures and provide customer service program each other interactive interface. 

  •   Remote then invoked (Remote Reference) layer.    This layer above the equivalent in its Stub / Skeleton in the under layer and the transport protocol layer before middleware, responsible for handling remote object cited the creation and management. 

  •   Finally, transfer protocol (Transport Protocol) layer.    The agreement of the data provided to customers through the transmission lines procedures and the remote object requests and responses. 

  These layers can refer to the interaction between the diagram below: 

  Distributed Object and other mechanisms, Java RMI customers to use client Stub object request to a remote method invocation; server object through the server-side Skeleton accept the request.    We get in-depth, look at some of these details. 

  NOTE: In fact, Java 1.2, RMI no longer need Skeleton object, but through the reflection mechanism Java (Reflection) to complete on the server side of the remote object invocation.    In order to facilitate the issue, the paper Skeleton based on the following elements still to explain. 

  When clients call Stub, Stub will be responsible for method parameters for the conversion of the sequence (Serialized) forms, we use a special terminology, which made (Marshal) to refer to the this process.    The provision of these parameters to be converted to be in the form of transplantation, which can be transmitted to a remote network services side.    Unfortunately, this process did not imagine that simple.    Here, we must first understand a classic issue, which is the method invocation, parameter values or whether Chuan Chuan cited?    The Java RMI, there are four, we will be noted. 

  •   The basic primitive types (integer, character, etc.), will be automatically sequence, the way to-value provision. 

  •   The Java objects, if the sequence of the object can be (achieved java.io.Serializable interface), through Java serialization mechanism to automatically sequence, the way to-value provision.    Included in the original object types, as well as all the targets were cited, and no statement for transient objects will automatically sequence of.    These, of course, been used must also be the object of the sequence can be. 

  •   The vast majority of the built-in Java objects are of the sequence can be.    The sequence of the non-Java Objects (java.io.File most typical), or an object contained in the sequence, and no other statement for transient object.    The provision of client programs will be dished out abnormal, and pronounced a failure. 

  •   Clients can call remote objects, there is no reason to prohibit call parameter itself is remote object (achieved java.rmi.Remote interface instance of the class).     At that time, RMI adoption of a simulated-use way (certainly not the traditional mass quoted as local memory to the application of the remote become meaningless), and not the parameters will be made directly to the remote replication.      Under such circumstances, the two sides interact in the dramatic changes which merits our attention.      Parameter is remote object, which means that the parameter object can be remote call.      When a customer procedures specified remote object as a parameter called the server-side methods of remote objects, RMI runtime server-side mechanism will send remote object as a parameter of a remote object Stub object.      This server-side remote callback object can be (Callback) Stub object of this method, then call in the client's remote objects corresponding methods.      Through this method, the server-side remote object as a parameter can be modified client remote object's internal state, which is traditionally used by a mass character.      Is not a halo?      The key here is to understand that in a distributed environment, the so-called server and client are relative.      By the requesting party is the server, and the requesting party is the client.  

  Call parameters in the process of the presentation after the success of the Remote Client Stub quoted layer obtained from the provision, as well as the parameters of the server remotely invoke the remote object (see java.rmi.server.RemoteRef API).    The layer will be responsible for clients based on the request of the bottom of the RMI data transport layer protocol conversion for the request.    In the RMI, a wide range of possible transmission mechanisms, such as peer-to-peer (Point-to-Point), and Broadcasting (Multicast).    However, the current version only supports JMI point-to-point agreement that will generate long-range use of the transport-layer only request, sent to the designated only remote object (see java.rmi.server.UnicastRemoteObject API). 

  In the server, the server-side use of the remote transmission of the requests received, and convert them to the remote object server-agent target Skeleton call.    Skeleton object will be responsible for the actual request for the conversion of the Remote Method Invocation object.    This is achieved through the provision of the anti-relative provision (Unmarshal) process to achieve.    Sequence all of the parameters are converted to the form of Java, including the remote object as a parameter (in fact sent to remote quoted) were converted into the local Stub server-side objects. 

  If Method Invocation dished out a return value or abnormal, Skeleton responsible for the return value, or are abnormal, through use of remote server layer, the transport layer transfer to the client; Accordingly, the use of remote client layer and Stub responsible for the provision and ultimately anti - Results will be back to the client. 

  Throughout the process, may be the most confusing is the use of the remote.    As long as that here, the local Stub how the object is not difficult to understand the significance of the long-range use of the.    Remote included in the quoted it at the remote object information, which will be used for the construction of long-distance as local agents targeted Stub object.    Construction, Stub internal target will be to safeguard the long-range use.    Really on the network transmission distance is actually used this, rather than Stub object. 

  4. RMI Object Service 

  RMI in the basic architecture, RMI provide services and distributed applications targeted a number of services, including the naming of object / Registration (Naming / Registry), remote object activation (Activation) services, as well as distributed garbage collection (Distributed Garbage Collection, DGC).    As a Getting Started Guide, the paper on which the naming Jiangzhi / registration services, because it is essential to combat RMI.    Other content on its own reference other readers more in-depth information. 

  The first one, if you like Baogenwende may have already noticed that the client calls to remote objects, through their agents targeted Stub completed, it is where the earliest Stub come from?    RMI naming / registration service is the solution of this problem.    When the server to the client to provide services based on the RMI, it will need one or more remote object registered to the local RMI registry (see java.rmi.registry.Registry API).    Each object has been registered in a specified future for the client to invoke the object's name.    Clients through Naming Service (see java.rmi.Naming API), similar to the designated name of the object on the URL at the remote objects can be invoked remotely.    Naming in the lookup () method to find remote object of the host, will host the retrieval of the RMI registry, and the request remote object.    If the registry was found in the remote object request, it will generate a remote object to the use of long-range, and their return to the client, the client is based on long-range quoted generate corresponding Stub object, and passed by reference to the caller.    After the two sides can be discussed in accordance with our previous approach to the interaction. 

  NOTE: RMI named Naming of the provision of services is not your only choice.    RMI registry can be bundled with other naming services, such as JNDI, so you can JNDI to visit the RMI registry. 

  5. Combat RMI 

  Theory is inseparable from practice, RMI understanding of the best way is through example.    RMI development of the Distributed Object the general process includes the following steps: 

  1.   Remote interface definition.    This step is through the expansion of java.rmi.Remote interface, and defines the operational requirements of the method. 

  2.   The realization of the definition of remote interface.    That is, to achieve the step by the definition of the interface, business methods are given a concrete realization of logic. 

  3.   Compiler remote interface and implementation class, and through RMI rmic compiler generates the necessary based on the realization of the Stub and Skeleton category. 

  RMI in the relationship between the various components such as the diagram shown below: 

  We recalled at a speech, Stub and Skeleton agent responsible for the client and server to communicate.    But we do not need to generate their own, on the contrary, RMI rmic compiler can help us achieve Based on Remote interface and category formation of these categories.    When the client-server through the naming service to the end of the RMI registry at the request of remote objects, RMI will be automatically constructed counterpart remote objects Skeleton examples of targets, and targets through remote Skeleton quoted back to the client.    On the client side, the remote will be used for the construction of Stub instance of the class object.    , Stub objects, and objects can Skeleton Acting clientele and remote interaction between the object. 

  We show examples of the application of a simple scene.    Server-side deployment of a calculation engine, to receive from the client computing tasks in the implementation of server-side computing tasks, and the results back to the client.    Client will be sent and call the calculation engine is actually computing tasks specified accuracy of the value of Ï€. 

  Important: This article adapted from the example of The Java? Tutorial Trail: RMI.    All rights belong to the corresponding all. 

  6. Definition Remote Interface 

  Remote interface definition and the definition of non-distributed applications in the interface method there is not much difference.    As long as compliance with the following two requirements: 

  •   Remote Interface must be directly or indirectly from the expansion of java.rmi.Remote interface.    Remote Interface also can be extended on the basis of the interface, and expansion of other interfaces, as long as the expansion interface of all methods and remote interface to meet all the same way under a request. 

  •    In the remote interface or its ultra-interface (Super-interface) statement methods must meet the following requirements  of the remote method:  

    •   Remote Method must declare java.rmi.RemoteException dished out abnormal, or the abnormal super-category (Superclass), for example, java.io.IOException java.lang.Exception or abnormal.    On this basis, the statement remote method can be dished out other application specific abnormality. 

    •   In the remote method statement, as a parameter or return value of the remote object, or included in other non-remote objects in the remote object should be required to declare their counterparts remote interface, rather than the actual implementation class. 

      Note: Java 1.2, dished out the above anomaly on the more stringent requirements that must be dished out java.rmi.RemoteExcption not to allow similar java.io.IOException such a super class.    The reason now to relax this requirement, the definition is so that we can both can be used for remote objects, can also be used to target the local interface easier (EJB think in the local interface and remote interface).    Of course, this does not mean that a good number of problems, you still have to declare anomaly.    However, the view is that this is not the issue, the mandatory statement abnormal developers can remain sober-minded, because local and remote objects in the object-calling when the semantic Senate is different.    Chuan cited local targets, and is targeted at the remote-value, it will mean that the internal state parameters of the outcome of the amendment is different. 

      For the first request, java.rmi.Remote interface virtually any means, but only for the marker interface.    RMI operating environment rely on the judgement whether the interface is the remote object.    The second requirement is possible because any distributed application problems, such as network problems, and so on. 

      Example 1 lists our remote interface definition.    The interface There is only one way: executeTask () for the specified computing tasks, and return to the desired results.    Note that we use the word Remote interface that is remote interface. 

      Example 1. ComputeEngineRemote Remote Interface 

      Package rmitutorial; import java.rmi.Remote; import java.rmi.RemoteException; public interface ComputeEngineRemote extends Remote (public Object executeTask (Task task) throws RemoteException;) 

      Cases 2 lists the interface definition computing tasks.    The interface only one way: execute () to the actual implementation of the calculation logic, and returns the results.    Note that the interface is not remote interface, there is no expansion of java.rmi.Remote interface; its methods do not have dished out java.rmi.RemoteException anomaly.    However, because it will for the remote method parameters, it extends java.io.Serializable interface. 

      Example 2. Task interface 

      Package rmitutorial; import java.io.Serializable; public interface Task extends Serializable (Object execute ();) 

      7. Remote Interface 

      Next, we will achieve in front of the definition of remote interface.    Example 3 is the realization of the source code. 

      Example 3. Achieve ComputeEngine 

      Package rmitutorial; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; public class ComputeEngine extends UnicastRemoteObject implements ComputeEngineRemote (public ComputeEngine () throws RemoteException (super ();) public Object executeTask (Task task) throws RemoteException (return task.execute ();)) 

      Class ComputeEngine before realizing the definition of a remote interface, inherited from the ultra-java.rmi.server.UnicastRemoteObject category.    UnicastRemoteObject category is a convenient category, it achieved what we have in front of the TCP / IP-based peer-to-peer communication mechanism.    Remote objects must be from such expansion (unless you want to achieve almost all UnicastRemoteObject methods).    In our realization of the constructor function, call the constructor of the super-function (of course, even if you do not explicitly call this building function, it will be the same call. Do so here, just to highlight this call only ).    The constructor function of the most important is the significance of the call UnicastRemoteObject exportObject () method.    Export (Export) target remote object is directed ready to accept the incoming call process.    This process is the most important part of the establishment of the server socket, monitoring specific ports, waiting for the call requesting client. 

      8. Boot 

      To enable our clients can find the remote object, we need to be registered to the remote object RMI registry.    This process is sometimes known as the "guide" process (Bootstrap).    To that end we will prepare an independent guide the process responsible for the creation and registration of remote object.    Example 4 is a guide program's source code. 

      Example 4. Boot 

      Package rmitutorial; import java.rmi.Naming; import java.rmi.RMISecurityManager; public class Bootstrap (public static void main (String [] args) throws Exception (String name = "ComputeEngine" ComputeEngine engine = new ComputeEngine (); System . out.println ( "ComputerEngine exported"); Naming.rebind (name, engine); System.out.println ( "ComputeEngine bound");)) 

      Can see, we first create a remote object (the object is derived at the same time), after binding to the target RMI registry.    Naming the rebind () method acceptable form of the name of a URL for bonding purposes.    It is complete the following form: 

      Protocol: / / host: port / object 

       The agreement (Protocol) by default rmi; hostname localhost by default; port defaults to 1099.      Note that the default provided in the JDK Naming achieve only support rmi agreement.      In the process inside our guidance is given only the name of the object binding, while other parts of the default values.  

      9. Client program 

      5 cases presented our clients.    The procedure accept two parameters, namely the remote object of the host address, and want the accuracy of the Ï€. 

      Example 5. Client.java 

      Package rmitutorial; import java.math.BigDecimal; import java.rmi.Naming; public class Client (public static void main (String args []) throws Exception (String name = "rmi: / /" + args [0] + " / ComputeEngine "; ComputeEngineRemote engineRemote = (ComputeEngineRemote) Naming.lookup (name); new Pi Pi task = (Integer.parseInt (args [1])); BigDecimal pi = (BigDecimal) (engineRemote.executeTask (task)); System . out.println (pi);)) 

      Case 6. Pi.java 

      Package rmitutorial; import java.math .*; public class Pi implements Task (private static final BigDecimal ZERO = BigDecimal.valueOf (0); private static final BigDecimal ONE = BigDecimal.valueOf (1); private static final BigDecimal FOUR = BigDecimal. valueOf (4); private static final int roundingMode = BigDecimal.ROUND_HALF_EVEN; private int digits; public Pi (int digits) (this.digits = digits;) public Object execute () (return computePi (digits);) public static BigDecimal computePi (int digits) (int scale digits + = 5; BigDecimal arctan1_5 = arctan (5 scale); BigDecimal arctan1_239 = arctan (239, scale); BigDecimal pi = arctan1_5.multiply (FOUR). subtract (arctan1_239). multiply (FOUR ); return pi.setScale (digits, BigDecimal.ROUND_HALF_UP);) public static BigDecimal arctan (int inverseX, int scale) (BigDecimal result, the numer, term; BigDecimal invX = BigDecimal.valueOf (inverseX); BigDecimal invX2 = BigDecimal.valueOf (inverseX inverseX *); numer = ONE.divide (invX, scale, roundingMode); result = numer; int i = 1; do numer = (numer.divide (invX2, scale, roundingMode); int denom = 2 * i + 1; term = numer.divide (BigDecimal.valueOf (denom), scale, roundingMode) if ((i% 2)! = 0) (result = result.subtract (term);) else (result.add result = ( term);) i + +;) while (term.compareTo (ZERO)! = 0); return result;)) 

      10. Compiled examples of procedures 

      We compiled examples of procedures and other non-compiler Distributed Application no distinction.    After compiling only need to use RMI compiler, which generates the necessary Stub rmic and Skeleton achieve.    Rmic way is to use our long-range target of the realization of (not remote interface) of the whole class name as a parameter to run rmic orders.    Reference to the following examples: 

      E: \ classes \ rmic rmitutorial.ComputeEngine 

      After the compiler will generate rmitutorial.ComputeEngine_Skel and rmitutorial.ComputeEngine_Stub two categories. 

      11. Operating procedures Example 

      Remote objects usually used by RMI registry services, as well as access to the java.rmi.Naming interface.    Remote object needs Export (Registration) applied to the corresponding remote registry service, followed registry services can be monitored and client services in remote object reference to the request.    Standard Sun Java SDK provides a simple RMI registry service procedures, which rmiregistry for monitoring specific ports, waiting for the remote object registration, as well as the client of these remote object reference retrieval request. 

      Examples of operational procedures before we, first of all, to start RMI registry services.    This process is as simple as can be ordered directly run rmiregistry.    Default case, the service will monitor port 1099.    If you need to monitor other designated ports can be specified in the command line that monitor port (if you specify other ports need to revise procedures to adapt to the environment example).    If you want the program runs in the background in Unix can be run in the following manner (of course, the port could default parameters): 

      $ 1099 & rmiregistry 

      In the Windows operating system can run: 

      C: \> start rmiregistry 1099 

      Our rmitutorial.Bootstrap category will be used to launch long-range targets, and its bundled in the RMI registry.    After such operation, remote object will also enter a state monitor and wait for the client from the method invocation request. 

      $ Java rmitutorial.Bootstrap ComputeEngine exported ComputeEngine bound 

      Activated remote object, open another command line window, running client.    The first command line parameter for the RMI registry address, and the second parameter for the expected value of Ï€ accuracy.    Reference to the following examples: 

      $ 50 3.14159265358979323846264338327950288419716939937511 java rmitutorial.Client localhost 

      12. Other information 

      Examples of procedures in the demonstration, we are actually running on the mainframe in the same server and client, and both the server and client in the category for the same type paths, server and can be visited by the client.    This Java RMI overlooked an important detail, namely, Dynamic Class Loading.    RMI because of the characteristics (including several other characteristics) does not apply to the RMI-IIOP J2EE EJB technology and, therefore, will not be detailed in this paper, please refer readers own this paper reference.    However, in order to allow the curious readers not too disappointed, briefly tell us about the dynamic loading of the basic idea. 

      RMI runtime system uses dynamic class loading mechanism to load the necessary distributed application category.    If you can directly access all the applications involved, including client-server, mainframe, and can be distributed applications for all categories are installed in each host CLASSPATH (the above example is an extreme case, all everything in the local host), then you do not have to concern RMI fully loaded category details.    Obviously, since it is distributed application, the situation is often quite to the contrary.    The RMI application, the client needs of the client self-loading the required categories, will be called the remote object of the remote interface, as well as the corresponding Stub; server should load remote object category, as well as the realization of the corresponding Skeleton category (Java 1.2 After no need Skeleton).    RMI involved in dealing with the long-distance call remote invoked, parameters and return values, can be a designated URL encoding to flow.    Cross the other end of the URL can be dealt with the target of the type of document required.    This is similar to the CODEBASE Applet the concept of interaction at both ends of their respective releases via HTTP server-like control, allowing the other end of dynamic interactive download these classes.    Examples of our example, not the client deployment ComputeEngine_Stub class files, and can be server-side access to the HTTP server class files.    Similarly, the server does not need to be customized to achieve the client tasks Pi class files. 

      Note that this dynamic class loading will be required at both ends of the interactive load customized security management (see java.rmi.RMISecurityManager API), as well as the corresponding strategy document. 

      13. BRIEF 

    •   The Java? Tutorial Trail: RMI 

    •    David Flanagan, Jim Farley, William Crawford and Kris Magnusson, 1999, ISBN 1-56592-483-5E, O'Reilly, the Java Enterprise in a Nutshell  

    •    Ed Roman, Scott Ambler and Tyler Jewell 2002, ISBN 0-471-41711-4, John Wiley & Sons, Inc, Matering Enterprise JavaBeans?, Second Edition  

      Posted on 2006-10-11 09:51 boddi reading (123) Comments (0) edit collections cited 

    Apache, rein pan-domain, multi-domain settings

      Apache, resin pan-domain, multi-domain settings 

      Version: httpd-2.2.4, 3.0.19 resin - 
      Pan-domain: 

    Apache:

      <VirtualHost *:80> 
      DocumentRoot / usr / local / pengpeng / xspace / 
      ServerName x.243.com 
      ServerAlias *. x.243.com 
      </ VirtualHost> 

      <VirtualHost *:80> 
      DocumentRoot / usr / local / pengpeng / xhome / 
      ServerName home.243.com 
      ServerAlias *. home.243.com 
      </ VirtualHost> 
    Resin:
      <host Id="home.243.com" root-directory="."> 
      <host-alias-regexp> ^([^/]*). Home.243.com </ host-alias-regexp> 
      <redeploy-mode> Manual </ redeploy-mode> 
      <web-app Id="/" document-directory="/usr/local/pengpeng/xhome/"/> 
      </ Host> 
      <host Id="x.243.com" root-directory="."> 
      <host-alias-regexp> ^([^/]*). X.243.com </ host-alias-regexp> 
      <redeploy-mode> Manual </ redeploy-mode> 
      <web-app Id="/" document-directory="/usr/local/pengpeng/xspace/"/> 
      </ Host> 

      Multi-domain: 

      Apache: 
      <VirtualHost *:80> 
      DocumentRoot / usr / local / pengpeng / channel / 
      ServerName blog.pengpeng.com 

      RewriteEngine On 

      # From the "Host:" ServerName head, the case may be mixed 
      RewriteMap lowercase int: tolower 

      # Check hostname correct or not, play a role only after the RewriteRule 
      RewriteCond $ (lowercase:% (HTTP_HOST)) ^ blog.pengpeng.com (.*)$ 
      RewriteCond% (REQUEST_URI) !^/(.+ \. Do) $ 

      RewriteRule ^ / index.jsp $ / blog / index.jsp [PT] 

      </ VirtualHost *: 80> 

      <VirtualHost *:80> 
      DocumentRoot / usr / local / pengpeng / channel / 
      ServerName show.pengpeng.com 

      RewriteEngine On 

      # From the "Host:" ServerName head, the case may be mixed 
      RewriteMap lowercase int: tolower 

      # Check hostname correct or not, play a role only after the RewriteRule 
      RewriteCond $ (lowercase:% (HTTP_HOST)) ^ show.pengpeng.com (.*)$ 
      RewriteCond% (REQUEST_URI) !^/(.+ \. Do) $ 

      RewriteRule ^ / index.jsp $ / show / index.jsp [PT] 

      </ VirtualHost *: 80> 

      <VirtualHost *:80> 
      DocumentRoot / usr / local / pengpeng / channel / 
      ServerName photo.pengpeng.com 

      RewriteEngine On 

      # From the "Host:" ServerName head, the case may be mixed 
      RewriteMap lowercase int: tolower 

      # Check hostname correct or not, play a role only after the RewriteRule 
      RewriteCond $ (lowercase:% (HTTP_HOST)) ^ photo.pengpeng.com (.*)$ 
      RewriteCond% (REQUEST_URI) !^/(.+ \. Do) $ 

      RewriteRule ^ / index.jsp $ / photo / index.jsp [PT] 

      </ VirtualHost *: 80> 
    Resin:

      <host Id="channel.pengpeng.com" root-directory="."> 
      <host-alias> Blog.pengpeng.com </ host-alias> 
      <host-alias> Show.pengpeng.com </ host-alias> 
      <host-alias> Photo.pengpeng.com </ host-alias> 
      <web-app Id="/" document-directory="/usr/local/pengpeng/channel/"/> 
      </ Host> 

      Reference: http://man.chinaunix.net/newsoft/Apache2.2_chinese_manual/index.html 
      Posted on 2007-06-14 14:06 hyq Reading (88) Comments (0) edit collections cited 

    keep looking »