<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    常用鏈接

    統(tǒng)計

    最新評論

    2011年1月17日 #

    Create Struts 2 Application in Eclipse : HTTP Status 500

    http://viralpatel.net/blogs/2009/12/tutorial-create-struts-2-application-eclipse-example.html 

    problem:

    HTTP Status 500 

    java.lang.NullPointerException 	
    org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    resolve problem:
    1. struts.xml should under src
    2. in struts.xml:  
    <action name="login" method="excute"
    class="net.viralpatel.struts2.LoginAction">

    posted @ 2012-04-21 02:41 九寶 閱讀(399) | 評論 (0)編輯 收藏

    How to check file properties through WMI command line (fw)

    How to check file properties through WMI command line

    24.Sep.2009 | by Gusac | Filed in: Articles, Tutorials

    With the lack of Graphical Interface on Windows 2008 Core server there comes a need of performing a lot of task through command line. One of which is checking file properties like file version, path, product verision etc. Luckily we have a command that makes this task simple. On a side note, We can also run the same command on other operating systems like Windows Xp, 2003, vista.

    Here is the command:
    wmic datafile where name='c:\\windows\\system32\\notepad.exe'

    Click here to view the enlarged screenshot

    Notice that we have used two backslashes \\ in the file path. Also, notice that the path is enclosed in the single quotes.
    The output will be confusing to read in command prompt window. To read and understand it better, we can take the output in text format and read it in notepad.

    While doing so, please do NOT wrap the text.
    wmic datafile where name='c:\\windows\\system32\\notepad.exe' > out.txt

    Click here to view the enlarged screenshot

    The output will reveal the file properties like Hidden, Path, Drive, Version Caption, Access rights etc.

    To get one particular property of a file we need to modify the command a little bit. We need to use the GET Alias injunction to the command mentioned above. Let's say we want to check the version for the file notepad.exe. The command that is used for this is:
    wmic datafile where name='c:\\windows\\system32\\notepad.exe' get version

    Similarily, there is a list of properties that can be fetched through this command line. They are:

    Access Rights
    Caption
    Class Name
    Compressed
    Compression Method
    Computer System Class Name
    Computer System Name
    Creation Date
    Current File Open Count
    Description
    Drive
    Eight Dot Three File Name
    Encrypted
    Encryption Method
    File Extension
    File Name
    File System Class Name
    File System Name
    File Type
    Hidden
    Install Date
    Last Accessed
    Last Modified
    Manufacturer
    Name
    Path
    Readable
    Should Be Archived
    Size
    Status
    System File
    Version
    Writeable

    posted @ 2011-12-07 22:29 九寶 閱讀(360) | 評論 (0)編輯 收藏

    Windows Authentication

    from http://www.iis.net/ConfigReference/system.webServer/security/authentication/windowsAuthentication

    Overview

    The <windowsAuthentication> element defines configuration settings for the Internet Information Services (IIS) 7 Windows authentication module. You can use Windows authentication when your IIS 7 server runs on a corporate network that is using Microsoft Active Directory service domain identities or other Windows accounts to identify users. Because of this, you can use Windows authentication whether or not your server is a member of an Active Directory domain.

    Windows authentication (formerly named NTLM, and also referred to as Windows NT Challenge/Response authentication) is a secure form of authentication because the user name and password are hashed before being sent across the network. When you enable Windows authentication, the client browser sends a strongly hashed version of the password in a cryptographic exchange with your Web server.

    Windows authentication supports two authentication protocols, Kerberos and NTLM, which are defined in the <providers> element. When you install and enable Windows authentication on IIS 7, the default protocol is Kerberos. The <windowsAuthentication> element can also contain a useKernelMode attribute that configures whether to use the kernel mode authentication feature that is new to Windows Server 2008.

    Windows authentication is best suited for an intranet environment for the following reasons:

    • Client computers and Web servers are in the same domain.
    • Administrators can make sure that every client browser is Internet Explorer 2.0 or later.
    • HTTP proxy connections, which are not supported by NTLM, are not required.
    • Kerberos version 5 requires a connection to Active Directory, which is not feasible in an Internet environment.

    New in IIS 7.5

    The <extendedProtection> element was introduced in IIS 7.5, which allows you to configure the settings for the new extended protection features that have been integrated into Windows authentication.

    Compatibility

    Version Notes
    IIS 7.5 The <extendedProtection> element was added in IIS 7.5.
    IIS 7.0 The <windowsAuthentication> element was introduced in IIS 7.0.
    IIS 6.0 The <windowsAuthentication> element replaces portions of the IIS 6.0 AuthType and AuthFlags metabase properties.

    Setup

    The default installation of IIS 7 does not include the Windows authentication role service. To use Windows authentication on IIS, you must install the role service, disable Anonymous authentication for your Web site or application, and then enable Windows authentication for the site or application.

    Note: After you install the role service, IIS 7 commits the following configuration settings to the ApplicationHost.config file.

    <windowsAuthentication enabled="false" />

    Windows Server 2008 or Windows Server 2008 R2

    1. On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
    2. In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
    3. In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
    4. On the Select Role Services page of the Add Role Services Wizard, select Windows Authentication, and then click Next.
    5. On the Confirm Installation Selections page, click Install.
    6. On the Results page, click Close.

    Windows Vista or Windows 7

    1. On the taskbar, click Start, and then click Control Panel.
    2. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
    3. Expand Internet Information Services, then World Wide Web Services, then Security.
    4. Select Windows Authentication, and then click OK.

    How To

    How to enable Windows authentication for a Web site, Web application, or Web service

    1. Open Internet Information Services (IIS) Manager:
      • If you are using Windows Server 2008 or Windows Server 2008 R2:
        • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
      • If you are using Windows Vista or Windows 7:
        • On the taskbar, click Start, and then click Control Panel.
        • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    2. In the Connections pane, expand the server name, expand Sites, and then the site, application, or Web service for which you want to enable Windows authentication.
    3. Scroll to the Security section in the Home pane, and then double-click Authentication.
    4. In the Authentication pane, select Windows Authentication, and then click Enable in the Actions pane.

    How to enable Extended Protection for Windows authentication

    1. Open Internet Information Services (IIS) Manager:
      • If you are using Windows Server 2008 or Windows Server 2008 R2:
        • On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
      • If you are using Windows Vista or Windows 7:
        • On the taskbar, click Start, and then click Control Panel.
        • Double-click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
    2. In the Connections pane, expand the server name, expand Sites, and then the site, application, or Web service for which you want to enable Extended Protection for Windows authentication.
    3. Scroll to the Security section in the Home pane, and then double-click Authentication.
    4. In the Authentication pane, select Windows Authentication.
    5. Click Enable in the Actions pane.
    6. Click Advanced Settings in the Actions pane.
    7. When the Advanced Settings dialog box appears, select one of the following options in the Extended Protection drop-down menu:
      • Select Accept if you want to enable extended protection while providing down-level support for clients that do not support extended protection.
      • Select Required if you want to enable extended protection without providing down-level support.
    8. Click OK to close the Advanced Settings dialog box.

    Configuration

    The <windowsAuthentication> element is configurable at the site, application, or virtual directory level in the ApplicationHost.config file.

    Attributes

    Attribute Description
    authPersistNonNTLM Optional Boolean attribute.

    Specifies whether IIS automatically reauthenticates every non-NTLM (for example, Kerberos) request, even those on the same connection. False enables multiple authentications for the same connections.

    Note: A setting of true means that the client will be authenticated only once on the same connection. IIS will cache a token or ticket on the server for a TCP session that stays established.

    The default is false.
    authPersistSingleRequest Optional Boolean attribute.

    Setting this flag to true specifies that authentication persists only for a single request on a connection. IIS resets the authentication at the end of each request, and forces reauthentication on the next request of the session.

    The default value is false.
    enabled Required Boolean attribute.

    Specifies whether Windows authentication is enabled.

    The default value is false.
    useKernelMode Optional Boolean attribute.

    Specifies whether Windows authentication is done in kernel mode. True specifies that Windows authentication uses kernel mode.

    Kernel-mode authentication may improve authentication performance and prevent authentication problems with application pools that are configured to use a custom identity.

    As a best practice, do not disable this setting if you use Kerberos authentication and have a custom identity on the application pool.

    The default is true.

    Child Elements

    Element Description
    extendedProtection Optional element.

    Specifies extended protection options for Windows authentication.

    Note: This element was added in IIS 7.5.
    providers Optional element.

    Specifies security support providers used for Windows authentication.

    Configuration Sample

    The following default <windowsAuthentication> element is configured at the root ApplicationHost.config file in IIS 7.0, and disables Windows authentication by default. It also defines the two Windows authentication providers for IIS 7.0.

    <windowsAuthentication enabled="false">
       <providers>
          <add value="Negotiate" />
          <add value="NTLM" />
       </providers>
    </windowsAuthentication>

    The following example enables Windows authentication and disables Anonymous authentication for a Web site named Contoso.

    <location path="Contoso">
       <system.webServer>
          <security>
             <authentication>
                <anonymousAuthentication enabled="false" />
                <windowsAuthentication enabled="true" />
             </authentication>
          </security>
       </system.webServer>
    </location>

    Sample Code

    The following examples disable Anonymous authentication for a site named Contoso, then enable Windows authentication for the site.

    AppCmd.exe

    appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"False" /commit:apphost
    
    appcmd.exe set config "Contoso" -section:system.webServer/security/authentication/windowsAuthentication /enabled:"True" /commit:apphost

    Note: You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

    C#

    using System;
    using System.Text;
    using Microsoft.Web.Administration;
    
    internal static class Sample {
    
       private static void Main() {
    
          using(ServerManager serverManager = new ServerManager()) { 
             Configuration config = serverManager.GetApplicationHostConfiguration();
    
             ConfigurationSection anonymousAuthenticationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso");
             anonymousAuthenticationSection["enabled"] = false;
    
             ConfigurationSection windowsAuthenticationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso");
             windowsAuthenticationSection["enabled"] = true;
    
             serverManager.CommitChanges();
          }
       }
    }

    VB.NET

    Imports System
    Imports System.Text
    Imports Microsoft.Web.Administration
    
    Module Sample
       Sub Main()
          Dim serverManager As ServerManager = New ServerManager
          Dim config As Configuration = serverManager.GetApplicationHostConfiguration
    
          Dim anonymousAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "Contoso")
          anonymousAuthenticationSection("enabled") = False
    
          Dim windowsAuthenticationSection As ConfigurationSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication", "Contoso")
          windowsAuthenticationSection("enabled") = True
    
          serverManager.CommitChanges()
       End Sub
    End Module

    JavaScript

    var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
    adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
    
    var anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
    anonymousAuthenticationSection.Properties.Item("enabled").Value = false;
    
    var windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso");
    windowsAuthenticationSection.Properties.Item("enabled").Value = true;
    
    adminManager.CommitChanges();

    VBScript

    Set adminManager = CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
    adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
    
    Set anonymousAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/anonymousAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
    anonymousAuthenticationSection.Properties.Item("enabled").Value = False
    
    Set windowsAuthenticationSection = adminManager.GetAdminSection("system.webServer/security/authentication/windowsAuthentication", "MACHINE/WEBROOT/APPHOST/Contoso")
    windowsAuthenticationSection.Properties.Item("enabled").Value = True
    
    adminManager.CommitChanges()

    posted @ 2011-09-16 21:46 九寶 閱讀(645) | 評論 (0)編輯 收藏

    How To Determine if Your Computer Is 32-Bit or 64-Bit(forward)

    how to check window version

    run: Winver


    Here's How:
    1. Open the System Information

      Open the Start menu, and click on Programs -> Accessories -> System Tools -> System Information

       

    2. Look in the System Summary

      The System Information tool will display detailed information about your Windows operating system. Once opened it will show the "System Summary" – it’s an overview of your computer and operating system.

    3. Look for the System Type Item

      On the right hand side of the window you will see a list of items. Look for the item called "System Type".

      The value of this item will tell you whether your computer is 32-bit or 64-bit:

      • x86-based PC: It’s a 32-bit computer.
      • x64-based PC: It’s a 64-bit computer.

       

    posted @ 2011-09-16 03:34 九寶 閱讀(256) | 評論 (0)編輯 收藏

    ContentProvider分析

         摘要: ContentProvider何時創(chuàng)建呢?這是一個值得深思的問題?  據(jù)我這兩天的了解是在你要用到的時候才會調(diào)用ContentProvider的onCreate函數(shù)進行創(chuàng)建。你就會什么時候叫要用到的時候呢?比如你要查詢或刪除修改數(shù)據(jù)庫的時候通過ContentResolver的quire或delete來操縱數(shù)據(jù)時就會調(diào)用ContentProvider的onCreate函數(shù),若已經(jīng)創(chuàng)建了數(shù)...  閱讀全文

    posted @ 2011-02-18 14:51 九寶 閱讀(1863) | 評論 (0)編輯 收藏

    GestureDetector手勢識別類 (轉(zhuǎn))

    View是在onTouchEvent(MotionEvent event)里對用戶的動作做了一定的分析,從而通知我們是發(fā)生了點擊還是長按等事件。

    我們需要創(chuàng)建一個GestureDetector的對象,傳入listener對象,view接收到的onTouchEvent中將event傳給GestureDetector進行分析listener會回調(diào)給我們相應(yīng)的動作。其中GestureDetector.SimpleOnGestureListenerFramework幫我們簡化了)是實現(xiàn)了上面提到的OnGestureListenerOnDoubleTapListener兩個接口的類,我們只需要繼承它并重寫其中我們關(guān)心的回調(diào)即可。

    ,那么,這個類如何使用呢?以下是使用該類的一個范例:

    private GestureDetector mGestureDetector;

    @Override

    public void onCreate(Bundle savedInstanceState) {


      super.onCreate(savedInstanceState);


      mGestureDetector = new GestureDetector(this, new MyGestureListener());


    }


    @Override

    public boolean onTouchEvent(MotionEvent event) {

     return mGestureDetector.onTouchEvent(event); 

    /*  有關(guān)上面的 onTouchEvent方法,我們可以直接判斷MotionEvent的類型,

        對于手勢移動僅僅捕獲ACTION_MOVE即可,

        我們通過參數(shù)MotionEvent e1, MotionEvent e2,float distanceX, float distanceY可以獲取操作變化。

       比如 distanceX > 0 向右邊移動,distanceX < 0 則向左邊,distanceY > 0 向上滾動, distanceY < 0 向下滾動。

    */

    }


    class MyGestureListener extends GestureDetector.SimpleOnGestureListener{

      @Override

      public boolean onSingleTapUp(MotionEvent ev) {

        Log.d("onSingleTapUp",ev.toString());

        return true;

      }


      @Override

      public void onShowPress(MotionEvent ev) {

        Log.d("onShowPress",ev.toString());

      }


      @Override

      public void onLongPress(MotionEvent ev) {

        Log.d("onLongPress",ev.toString());

      }

    }

     


    更多的回調(diào)消息,方便的對用戶的動作進行響應(yīng)

    public interface OnGestureListener {

                    // Touch down時觸發(fā), edown時的MotionEvent

                    boolean onDown(MotionEvent e);

                    // Touch down之后一定時間(115ms)觸發(fā),edown時的MotionEvent

                    void onShowPress(MotionEvent e);

                    // Touch up時觸發(fā),eup時的MotionEvent

                    boolean onSingleTapUp(MotionEvent e);

                    // 滑動時觸發(fā),e1down時的MotionEvente2move時的MotionEvent

                    boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY);

                    // Touch down之后一定時間(500ms)觸發(fā),edown時的MotionEvent

                    void onLongPress(MotionEvent e);

                    // 滑動一段距離,up時觸發(fā),e1down時的MotionEvente2up時的MotionEvent

                    boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);

    } 

    public interface OnDoubleTapListener {

                    // 完成一次單擊,并確定沒有二擊事件后觸發(fā)(300ms),edown時的MotionEvent

                    boolean onSingleTapConfirmed(MotionEvent e);

                    // 第二次單擊down時觸發(fā),e為第一次down時的MotionEvent

                    boolean onDoubleTap(MotionEvent e);

                    // 第二次單擊down,moveup時都觸發(fā),e為不同時機下的MotionEvent

                    boolean onDoubleTapEvent(MotionEvent e);

    }

    boolean  onDoubleTap(MotionEvent e)
    解釋:雙擊的第二下Touch down時觸發(fā)
    boolean  onDoubleTapEvent(MotionEvent e)
    解釋:雙擊的第二下Touch down和up都會觸發(fā),可用e.getAction()區(qū)分。
    boolean  onDown(MotionEvent e)
    解釋:Touch down時觸發(fā)
    boolean  onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    解釋:Touch了滑動一點距離后,up時觸發(fā)。
    void  onLongPress(MotionEvent e)
    解釋:Touch了不移動一直Touch down時觸發(fā)
    boolean  onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
    解釋:Touch了滑動時觸發(fā)。
    void  onShowPress(MotionEvent e)
    解釋:Touch了還沒有滑動時觸發(fā)
    (與onDown,onLongPress比較,onDown只要Touch down一定立刻觸發(fā)。而Touchdown后過一會沒有滑動先觸發(fā)onShowPress再是onLongPress。
    所以Touchdown后一直不滑動,onDown->onShowPress->onLongPress這個順序觸發(fā)。
    boolean  onSingleTapConfirmed(MotionEvent e)
    boolean  onSingleTapUp(MotionEvent e)
    解釋:上面這兩個函數(shù)都是在touch down后又沒有滑動(onScroll),又沒有長按(onLongPress),然后Touchup時觸發(fā)。
    點擊一下非常快的(不滑動)Touchup:
    onDown->onSingleTapUp->onSingleTapConfirmed
    點擊一下稍微慢點的(不滑動)Touchup:
    onDown->onShowPress->onSingleTapUp->onSingleTapConfirmed


    posted @ 2011-02-16 15:03 九寶 閱讀(541) | 評論 (0)編輯 收藏

    onNewIntent 什么時候調(diào)用

    protected void onNewIntent (Intent intent)

    Since: API Level 1

    This is called for activities that set launchMode to "singleTop" in their package, or if a client used theFLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.

    An activity will always be paused before receiving a new intent, so you can count on onResume() being called after this method.

    Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.


    在IntentActivity中重寫下列方法:onCreate onStart onRestart  onResume  onPause onStop onDestroy  onNewIntent
    一、其他應(yīng)用發(fā)Intent,執(zhí)行下列方法:
    I/@@@philn(12410): onCreate
    I/@@@philn(12410): onStart
    I/@@@philn(12410): onResume

    發(fā)Intent的方法:
    Uri uri = Uri.parse("philn://blog.163.com");
    Intent it = new Intent(Intent.ACTION_VIEW, uri);    
    startActivity(it);

    二、接收Intent聲明:
     <activity android:name=".IntentActivity" android:launchMode="singleTask"
                      android:label="@string/testname">
                 <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <data android:scheme="philn"/>
                </intent-filter>
      </activity>

    三、如果IntentActivity處于任務(wù)棧的頂端,也就是說之前打開過的Activity,現(xiàn)在處于
    I/@@@philn(12410): onPause
    I/@@@philn(12410): onStop 狀態(tài)的話
    其他應(yīng)用再發(fā)送Intent的話,執(zhí)行順序為:
    I/@@@philn(12410): onNewIntent
    I/@@@philn(12410): onRestart
    I/@@@philn(12410): onStart
    I/@@@philn(12410): onResume

    posted @ 2011-02-14 11:18 九寶 閱讀(6204) | 評論 (1)編輯 收藏

    Observer模式在J2EE中的實現(xiàn) [http://35java.com/zhibo/forum.php?mod=viewthread&tid=108&extra=page%3D3]

    引言:
                設(shè)計模式是經(jīng)驗的文檔化。它是對被用來在特定場景下解決一般設(shè)計問題的類和相互通信的對象的描述。更通俗的來說,它是一個問題/解決方案對。一旦我們掌握了設(shè)計模式,就等于擁有了一支強有力的專家隊伍。它甚至能夠使面向?qū)ο蟮男率掷们叭说慕?jīng)驗找出職責(zé)明確的類和對象,從而獲得優(yōu)雅的解決方案。由于設(shè)計模式也是重構(gòu)的目標(biāo),如果在設(shè)計的初期適當(dāng)?shù)匾朐O(shè)計模式,可以減少重構(gòu)的工作量。
          但是,我們也不能陷入模式的陷阱,為了使用模式而去套模式,那樣會陷入形式主義。我們在使用模式的時候,一定要注意模式的意圖(intent),而不要過多的去關(guān)注模式的實現(xiàn)細(xì)節(jié),因為這些實現(xiàn)細(xì)節(jié)在特定情況下,可能會發(fā)生一些改變。不要頑固地認(rèn)為設(shè)計模式一書中的類圖或?qū)崿F(xiàn)代碼就代表了模式本身。
          下面,我們來討論一下為什么要在分布式、多層系統(tǒng)中使用Observer模式。
          

    多層體系結(jié)構(gòu)(multi-tier architecture):
                三層體系結(jié)構(gòu)是多層體系結(jié)構(gòu)中最簡單的一種,它一般包括:
          
    • 表示層(presentation)-窗口、報表-
    • 業(yè)務(wù)邏輯層(business logic)-管理業(yè)務(wù)過程的任務(wù)和規(guī)則。它又可以細(xì)分為領(lǐng)域?qū)ο髮樱ù眍I(lǐng)域概念)和服務(wù)層(提供數(shù)據(jù)庫交互、安全性、打印報表)。
    • 存儲層(storage)-持久化存儲機制。如數(shù)據(jù)庫服務(wù)器等。
                  
    圖一:三層體系結(jié)構(gòu)
                  
          而Java 2平臺企業(yè)版(J2EE)是一種利用Java 2平臺來簡化諸多與多級企業(yè)解決方案的開發(fā)、部署和管理相關(guān)的復(fù)雜問題的體系結(jié)構(gòu)。它是開放的、基于標(biāo)準(zhǔn)的平臺,用以開發(fā)、部署和管理N層結(jié)構(gòu)、面向Web的,以服務(wù)器為中心的企業(yè)級應(yīng)用。
          為了支持領(lǐng)域?qū)ο蟮膹?fù)用,并且使領(lǐng)域?qū)ο蟮慕涌谧兏鶐淼挠绊懽钚』N覀儗㈩I(lǐng)域?qū)樱P停┖捅硎緦樱ㄒ晥D)相分離。
          采用模型-視圖模式的意義在于:
          
    • 支持聚合度更高的模型定義,使模型的定義可以集中在領(lǐng)域過程的定義,而不是圖形界面上。
    • 允許將模型和用戶界面并行開發(fā)。
    • 使用戶界面的需求變化對領(lǐng)域?qū)铀斐傻挠绊懽钚』?/li>
    • 允許建立與一個現(xiàn)有的領(lǐng)域?qū)訉ο笙噙B接的新視圖,同時不影響領(lǐng)域?qū)印?/li>
    • 允許一個模型同時有多個視圖,例如使用SVG和表格。
    • 允許模型層獨立于用戶界面層執(zhí)行。
          而這恰恰與Observer模式的意圖相吻合。因此我們有必要跨層來實現(xiàn)Observer模式。
          其實,在應(yīng)用中更多的是采用MVC框架來架構(gòu)整個企業(yè)應(yīng)用的。在MVC框架中,Model和View之間存在著依賴關(guān)系,是Observer模式的典型應(yīng)用。當(dāng)然MVC框架還包括其它模式如Composite模式和Strategy模式。在J2EE平臺中,我們可以把Web Tier(包括Jsp和servelet和JavaBean)看作是表示層,EJB Tier看作是領(lǐng)域?qū)印6鴆ontroller可能跨距Web Tier和 EJB Tier。
          在Java類庫中采用Java.util.Observable類和Java.util.Observer接口來實現(xiàn)Observer模式,它們在單個的Java VM.中運行的很好,但如果想在EJB中使用它們就會有一些問題。這正如我們引言中提到的,模式的具體實現(xiàn)在特定情況下,可能會發(fā)生一些改變。
          

    值傳遞還是遠(yuǎn)程引用傳遞?
                        值傳遞:        
    在Java RMI中要求所有的參數(shù)和返回類型是JAVA的基本類型或?qū)崿F(xiàn)Java.io.Serilizable的對象。串行化對象通過值傳遞(又名拷貝傳遞),而不是引用傳遞,這意味著在某一層中串行化對象的更并不自動影響到其它的對象。      
                  遠(yuǎn)程引用傳遞:        
    對于EJB對象而言,它由兩個接口(home接口和remote接口)和一個類組成。容器會根據(jù)ejb規(guī)范來生成實現(xiàn)上面兩個接口的類(我們分別稱為xxxEJBHome對象和xxxEjbObject對象)。在較多的容器的實現(xiàn)方案中,xxxEJBHome對象使用了factory模式來創(chuàng)建xxxEjbObject對象;xxxEjbObject對象則采用proxy模式,作為xxxBean的代理類。在生成以上兩個對象的同時,容器會從部署文件中讀取關(guān)于安全、事務(wù)、持久性等服務(wù)并在xxxEjbObject對象和xxxEJBHome對象中添加以上服務(wù)的代碼。而且xxxEJBHome對象和xxxEjbObject對象都是分布式對象,我們在此只討論xxxEjbObject對象。所謂分布式對象,從本質(zhì)上來講,分為3個部分:object server、skeleton、stub。其中object server和skeleton位于服務(wù)器端,而stub位于客戶端。Object server負(fù)責(zé)實現(xiàn)業(yè)務(wù)邏輯,skeleton負(fù)責(zé)marshal和unmarshal方法簽名。      
                  
    圖二:分布式對象
                  
          顯然,EJB的客戶(調(diào)用EJB的對象)可以是任何對象,包括EJB和一般的Java類甚至是用任何語言寫的corba客戶端。
          從EJB的客戶視角來看的話,我們只能看到一個home接口、一個remote接口(對于實體bean的話,還可以看見一個主鍵類,而bean類對客戶是不可見的)。但我們從上面的論述,我們可以知道,對于remote接口中地方法調(diào)用,實際上是多態(tài)地調(diào)用XXX_Stub類。即XXX_Stub對象對客戶具有可見性(但這種可見性是透明的,即客戶不知道這種可見性的存在)。由于,XXX_Stub對象和Object Server實現(xiàn)了相同的接口,并且Object server真正實現(xiàn)了業(yè)務(wù)邏輯。所以,當(dāng)在客戶端調(diào)用XXX_Stub對象的方法時候,XXX_Stub對象通過socket通信機制將方法簽名傳給XXX_Skeleton對象,XXX_Skeleton對象在去委托Object Server完成業(yè)務(wù)處理邏輯。因此,Object Server本身發(fā)生了改變。我們稱XXX_Stub對象是Object Server對象的遠(yuǎn)程引用,并認(rèn)為當(dāng)分布式對象作為參數(shù)傳遞的時候,是通過引用傳遞的(會產(chǎn)生副作用

    posted @ 2011-02-13 19:24 九寶 閱讀(423) | 評論 (0)編輯 收藏

    RMI的定義(轉(zhuǎn))http://blog.csdn.net/ocean181/archive/2010/09/02/5857273.aspx

    RMI的定義

    Java RMI (Remote Method Invocation 遠(yuǎn)程方法調(diào)用)是用Java在JDK1.1中實現(xiàn)的,它大大增強了Java開發(fā)分布式應(yīng)用的能力。Java作為一種風(fēng)靡一時的網(wǎng)絡(luò)開發(fā)語言,其巨大的威力就體現(xiàn)在它強大的開發(fā)分布式網(wǎng)絡(luò)應(yīng)用的能力上,而RMI就是開發(fā)百分之百純Java的網(wǎng)絡(luò)分布式應(yīng)用系統(tǒng)的核心解決方案之一。其實它可以被看作是RPC的Java版本。但是傳統(tǒng)RPC并不能很好地應(yīng)用于分布式對象系統(tǒng)。而Java RMI 則支持存儲于不同地址空間的程序級對象之間彼此進行通信,實現(xiàn)遠(yuǎn)程對象之間的無縫遠(yuǎn)程調(diào)用。

    RMI目前使用Java遠(yuǎn)程消息交換協(xié)議JRMP(Java Remote Messaging Protocol)進行通信。JRMP是專為Java的遠(yuǎn)程對象制定的協(xié)議。因此,Java RMI具有Java的“Write Once,Run Anywhere”的優(yōu)點,是分布式應(yīng)用系統(tǒng)的百分之百純Java解決方案。用Java RMI開發(fā)的應(yīng)用系統(tǒng)可以部署在任何支持JRE(Java Run Environment Java,運行環(huán)境)的平臺上。但由于JRMP是專為Java對象制定的,因此,RMI對于用非Java語言開發(fā)的應(yīng)用系統(tǒng)的支持不足。不能與用非Java語言書寫的對象進行通信。

    RMI與CORBA的關(guān)系

    RMI 和CORBA常被視為相互競爭技術(shù),因為兩者都提供對遠(yuǎn)程分布式對象的透明訪問。但這兩種技術(shù)實際上是相互補充的,一者的長處正好可以彌補另一者的短處。RMI 和 CORBA 的結(jié)合產(chǎn)生了 RMI-IIOP,RMI-IIOP 是企業(yè)服務(wù)器端 Java 開發(fā)的基礎(chǔ)

    1997 年,IBM 和 Sun Microsystems啟動了一項旨在促進 Java 作為企業(yè)開發(fā)技術(shù)的發(fā)展的合作計劃。兩家公司特別著力于如何將 Java 用作服務(wù)器端語言,生成可以結(jié)合進現(xiàn)有體系結(jié)構(gòu)的企業(yè)級代碼。所需要的就是一種遠(yuǎn)程傳輸技術(shù),它兼有 Java 的 RMI(Remote Method Invocation,遠(yuǎn)程方法調(diào)用)較少的資源占用量和更成熟的 CORBA(Common Object Request Broker Architecture,公共對象請求代理體系結(jié)構(gòu))技術(shù)的健壯性。出于這一需要,RMI-IIOP問世了,它幫助將 Java 語言推向了目前服務(wù)器端企業(yè)開發(fā)的主流語言的領(lǐng)先地位。

    RMI的組成

    一個正常工作的RMI系統(tǒng)由下面幾個部分組成:

    1、遠(yuǎn)程服務(wù)的接口定義

    2、遠(yuǎn)程服務(wù)接口的具體實現(xiàn)

    3、樁(Stub)和框架(Skeleton)文件

    4、一個運行遠(yuǎn)程服務(wù)的服務(wù)器

    5、一個RMI命名服務(wù),它允許客戶端去發(fā)現(xiàn)這個遠(yuǎn)程服務(wù)

    6、類文件的提供者(一個HTTP或者FTP服務(wù)器)

    7、一個需要這個遠(yuǎn)程服務(wù)的客戶端程序

    RMI的實現(xiàn)

    下面我們一步一步建立一個簡單的RMI系統(tǒng)。首先在你的機器里建立一個新的文件夾,以便放置我們創(chuàng)建的文件,為了簡單起見,我們只使用一個文件夾存放客戶端和服務(wù)端代碼,并且在同一個目錄下運行服務(wù)端和客戶端。

    如果所有的RMI文件都已經(jīng)設(shè)計好了,那么你需要下面的幾個步驟去生成你的系統(tǒng):

    1、   編寫并且編譯接口的Java代碼
    2、   編寫并且編譯接口實現(xiàn)的Java代碼
    3、   從接口實現(xiàn)類中生成 Stub 和 Skeleton 類文件
    4、   編寫遠(yuǎn)程服務(wù)的主運行程序
    5、   編寫RMI的客戶端程序
    6、   安裝并且運行RMI系統(tǒng)

    1、接口

    第一步就是建立和編譯服務(wù)接口的Java代碼。這個接口定義了所有的提供遠(yuǎn)程服務(wù)的功能,下面是源程序:

       1. //Calculator.java
       2. //define the interface
       3. import java.rmi.Remote;
       4.
       5. public interface Calculator extends Remote
       6. {
       7.     public long add(long a, long b)
       8.         throws java.rmi.RemoteException;
       9.
      10.     public long sub(long a, long b)
      11.         throws java.rmi.RemoteException;
      12.
      13.     public long mul(long a, long b)
      14.         throws java.rmi.RemoteException;
      15.
      16.     public long div(long a, long b)
      17.         throws java.rmi.RemoteException;
      18. }


    注意,這個接口繼承自Remote,每一個定義的方法都必須拋出一個RemoteException異常對象。

    建立這個文件,把它存放在剛才的目錄下,并且編譯。

    >javac Calculator.java

    2、接口的具體實現(xiàn)

    下一步,我們就要寫遠(yuǎn)程服務(wù)的具體實現(xiàn),這是一個CalculatorImpl類文件:

       1. //CalculatorImpl.java
       2. //Implementation
       3. import java.rmi.server.UnicastRemoteObject;
       4.
       5. public class CalculatorImpl extends UnicastRemoteObject implements Calculator
       6. {
       7.
       8.     // 這個實現(xiàn)必須有一個顯式的構(gòu)造函數(shù),并且要拋出一個RemoteException異常
       9.     public CalculatorImpl()
      10.         throws java.rmi.RemoteException {
      11.         super();
      12.      }
      13.
      14.     public long add(long a, long b)
      15.         throws java.rmi.RemoteException {
      16.         return a + b;
      17.      }
      18.
      19.     public long sub(long a, long b)
      20.         throws java.rmi.RemoteException {
      21.         return a - b;
      22.      }
      23.
      24.     public long mul(long a, long b)
      25.         throws java.rmi.RemoteException {
      26.         return a * b;
      27.      }
      28.
      29.     public long div(long a, long b)
      30.         throws java.rmi.RemoteException {
      31.         return a / b;
      32.      }
      33. }


    同樣的,把這個文件保存在你的目錄里然后編譯他。

    這個實現(xiàn)類使用了UnicastRemoteObject去聯(lián)接RMI系統(tǒng)。在我們的例子中,我們是直接的從UnicastRemoteObject 這個類上繼承的,事實上并不一定要這樣做,如果一個類不是從UnicastRmeoteObject上繼承,那必須使用它的exportObject() 方法去聯(lián)接到RMI。

    如果一個類繼承自UnicastRemoteObject,那么它必須提供一個構(gòu)造函數(shù)并且聲明拋出一個RemoteException對象。當(dāng)這個構(gòu)造函數(shù)調(diào)用了super(),它久激活UnicastRemoteObject中的代碼完成RMI的連接和遠(yuǎn)程對象的初始化。

    3、Stubs 和Skeletons

    下一步就是要使用RMI編譯器rmic來生成樁和框架文件,這個編譯運行在遠(yuǎn)程服務(wù)實現(xiàn)類文件上。

    >rmic CalculatorImpl

    在你的目錄下運行上面的命令,成功執(zhí)行完上面的命令你可以發(fā)現(xiàn)一個Calculator_stub.class文件,如果你是使用的Java2SDK,那么你還可以發(fā)現(xiàn)Calculator_Skel.class文件。

    4、主機服務(wù)器

    遠(yuǎn)程RMI服務(wù)必須是在一個服務(wù)器中運行的。CalculatorServer類是一個非常簡單的服務(wù)器。

       1. //CalculatorServer.java
       2. import java.rmi.Naming;
       3.
       4. public class CalculatorServer {
       5.
       6.    public CalculatorServer() {
       7.      try {
       8.         Calculator c = new CalculatorImpl();
       9.        Naming.rebind("rmi://localhost:1099/CalculatorService", c);
      10.       } catch (Exception e) {
      11.        System.out.println("Trouble: " + e);
      12.       }
      13.     }
      14.
      15.    public static void main(String args[]) {
      16.      new CalculatorServer();
      17.     }
      18. }


    建立這個服務(wù)器程序,然后保存到你的目錄下,并且編譯它。

    5、客戶端

    客戶端源代碼如下:

       //CalculatorClient.java
       
        import java.rmi.Naming;
        import java.rmi.RemoteException;
        import java.net.MalformedURLException;
       import java.rmi.NotBoundException;
       
       public class CalculatorClient {
       
           public static void main(String[] args) {
             try {
                 Calculator c = (Calculator)
                                  Naming.lookup(
                        "rmi://localhost
                                /CalculatorService");
                   System.out.println( c.sub(4, 3) );
                System.out.println( c.add(4, 5) );
                   System.out.println( c.mul(3, 6) );
                  System.out.println( c.div(9, 3) );
                }
               catch (MalformedURLException murle) {
                   System.out.println();
                  System.out.println(
                     "MalformedURLException");
                   System.out.println(murle);
                }
               catch (RemoteException re) {
                  System.out.println();
                   System.out.println(
                              "RemoteException");
                   System.out.println(re);
               }
              catch (NotBoundException nbe) {
                  System.out.println();
                   System.out.println(
                              "NotBoundException");
                   System.out.println(nbe);
                }
               catch (
                   java.lang.ArithmeticException
                                             ae) {
                  System.out.println();
                  System.out.println(
                   "java.lang.ArithmeticException");
                 System.out.println(ae);
                }
           }
       }

    保存這個客戶端程序到你的目錄下(注意這個目錄是一開始建立那個,所有的我們的文件都在那個目錄下),并且編譯他。

    6、運行RMI系統(tǒng)

    現(xiàn)在我們建立了所有運行這個簡單RMI系統(tǒng)所需的文件,現(xiàn)在我們終于可以運行這個RMI系統(tǒng)啦!來享受吧。

    我們是在命令控制臺下運行這個系統(tǒng)的,你必須開啟三個控制臺窗口,一個運行服務(wù)器,一個運行客戶端,還有一個運行RMIRegistry。

    首先運行注冊程序RMIRegistry,你必須在包含你剛寫的類的那么目錄下運行這個注冊程序。

    >rmiregistry

    好,這個命令成功的話,注冊程序已經(jīng)開始運行了,不要管他,現(xiàn)在切換到另外一個控制臺,在第二個控制臺里,我們運行服務(wù)器CalculatorService,因為RMI的安全機制將在服務(wù)端發(fā)生作用,所以你必須增加一條安全策略。以下是對應(yīng)安全策略的例子
    grant {
    permission java.security.AllPermission "", "";
    };

    注意:這是一條最簡單的安全策略,它允許任何人做任何事,對于你的更加關(guān)鍵性的應(yīng)用,你必須指定更加詳細(xì)安全策略。

    現(xiàn)在為了運行服務(wù)端,你需要除客戶類(CalculatorClient.class)之外的所有的類文件。確認(rèn)安全策略在policy.txt文件之后,使用如下命令來運行服務(wù)器。

    > java -Djava.security.policy=policy.txt CalculatorServer

    這個服務(wù)器就開始工作了,把接口的實現(xiàn)加載到內(nèi)存等待客戶端的聯(lián)接。好現(xiàn)在切換到第三個控制臺,啟動我們的客戶端。

    為了在其他的機器運行客戶端程序你需要一個遠(yuǎn)程接口(Calculator.class) 和一個stub(CalculatorImpl_Stub.class)。 使用如下命令運行客戶端

    > java -Djava.security.policy=policy.txt CalculatorClient

    如果所有的這些都成功運行,你應(yīng)該看到下面的輸出:
    1
    9
    18
    3

    如果你看到了上面的輸出,恭喜你,你成功了,你已經(jīng)成功的創(chuàng)建了一個RMI系統(tǒng),并且使他正確工作了。即使你運行在同一個計算機上,RMI還是使用了你的網(wǎng)絡(luò)堆棧和TCP/IP去進行通訊,并且是運行在三個不同的Java虛擬機上。這已經(jīng)是一個完整的RMI系統(tǒng)。

    posted @ 2011-02-13 18:46 九寶 閱讀(258) | 評論 (0)編輯 收藏

    JavaBean PropertyChange 之設(shè)計模式Observer(轉(zhuǎn))

         摘要: java語言里包含了許多對設(shè)計模式的直接支持,如command模式,agent模式,observer模式等。雖然java提供的對這些模式的支持很簡單,不能滿足比較復(fù)雜的應(yīng)用。但在簡單的場景下,使用這些類往往能夠得到立桿見影的效果。所以,如果沒有什么特殊需求,還是最好利用java的這些類。         Observ...  閱讀全文

    posted @ 2011-02-13 18:26 九寶 閱讀(942) | 評論 (0)編輯 收藏

    (轉(zhuǎn))UML中類圖實例

    接口:空心圓+直線(唐老鴨類實現(xiàn)了‘講人話’);
    依賴:虛線+箭頭(動物和空氣的關(guān)系);
    關(guān)聯(lián):實線+箭頭(企鵝需要知道氣候才遷移);
    聚合:空心四邊形+實線+箭頭(雁群和大雁的關(guān)系);
    合成/組合:實心四邊形+實線+箭頭(鳥和翅膀的關(guān)系);
    泛化/
    繼承:空心三角形+實線(動物和鳥的繼承關(guān)系);
    實現(xiàn):空心三角形+虛線(實現(xiàn)大雁飛翔的接口);
    UML類圖  
    解釋
    UML類圖:
    1.       首先看“動物”矩形框,它代表一個類。該類圖分為三層,第一層顯示類的名稱,如果是抽象類就要用斜體顯示。第二層是類的特性,通常就是字段和屬性。第三層是類的操作,通常是方法和行為。
       注意前面的符號,‘+’表示public, ‘ 表示private, ‘#’表示protected.   
                                               
    2.       飛翔矩形框表示一個接口圖,它與類圖的區(qū)別主要是頂端有《interface》顯示,第一行是接口名稱,第二行是接口方法。接口還有另一種表示方法,俗稱棒棒糖表示法,就是唐老鴨類實現(xiàn)了“講人話”的接口。
                  
    interface IFly                              interface Ilanguage                              
    {                                              {
       
    void Fly();                                    void Speak();
    }                                             }

    3.       動物,鳥,鴨,唐老鴨他們之間都是繼承的關(guān)系,繼承關(guān)系用空心三角形+實現(xiàn)來表示   
                     

    4.“大雁”實現(xiàn)了“飛翔”接口。實現(xiàn)接口用空心三角形+虛線來表示。(注:下面的圖中應(yīng)為空心三角形

    class Bird:Animal                      class WideGoose:IFly
    {                                        {
       
    //繼承動物類                                 //實現(xiàn)飛翔接口
    }                                        }

    5.       企鵝與氣候有很大的關(guān)系,企鵝需要“知道”氣候的變化,需要“了解”氣候規(guī)律。當(dāng)一個類“知道”另一個類時,可以用關(guān)聯(lián)(association)關(guān)系。關(guān)聯(lián)關(guān)系用實線箭頭來表示  
         
    class Penguin :Bird
    {
       
    private Climate climate;//在企鵝Penguin中,引用到氣候Climate對象
    }

    6.       “大雁”和“雁群”這兩個類。大雁是群居動物,每只大雁都屬于一個雁群,一個雁群可以有多只大雁。所以它們之間就滿足聚合(Aggregation)關(guān)系。聚合表示一種弱的“擁有”關(guān)系,體現(xiàn)的是A對象可以包含B對象,但B對象不是A對象的一部分。聚合關(guān)系用空心的菱形+ 實線箭頭表示
        

    class WideGooseAggregate
    {
       
    private WideGoose[] arrayWideGoose;
       
    //在雁群WideGooseAggregate類中,有大雁數(shù)組對象arrayWideGoose
    }

    7.       “鳥”和“翅膀”這兩個類。鳥和翅膀似整體和部分的關(guān)系,并且翅膀和鳥的生命周期是相同的,在這里鳥和其翅膀就是合成關(guān)系。合成(composition)是一種強的“擁有”關(guān)系,體現(xiàn)了嚴(yán)格的部分和整體的關(guān)系,部分和整體的生命周期一樣合成關(guān)系用實心的的菱形+實線箭頭來表示。另外,合成關(guān)系的連線兩端還有一個數(shù)字“1”和數(shù)字“2”,,這被稱為基數(shù)。表明這一端的類可以有幾個實例,很顯然,一個鳥應(yīng)該有兩支翅膀。如果一個類可能有無數(shù)個實例,則就用“n”來表示。關(guān)聯(lián)關(guān)系,聚合關(guān)系也可以有基數(shù)的。
    class Bird 
    {
      
    private Wing wing;
      
    public Bird()
       {
          wing
    =new Wing();
        
    //在鳥Bird類中,初始化時,實例化翅膀Wing,它們之間同時生成
       }
    }

    8.       “動物”、“氧氣”與“水”之間。動物有幾大特征,比如有新陳代謝,能繁殖。而動物要有生命,需要氧氣,水以及食物等。也就是說動物依賴于氧氣和水。它們之間是依賴關(guān)系(Dependency),用虛線箭頭來表示

    abstract class Animal
    {
       
    public bolism(Oxygen oxygen,Water water)
        {
        } 
    }

    posted @ 2011-02-12 13:02 九寶 閱讀(355) | 評論 (0)編輯 收藏

    android register mimetype

    在manifest文件里->activity 添加

    <intent-filter>

         <action android:name="android.intent.action.VIEW" />

         <category android:name="android.intent.category.DEFAULT" />

         <data android:mimeType="*/*">

    </intent-filter>

    這樣就把當(dāng)前程序注冊為 可以打開/查看所有類型的文件. 或者要查看jpeg, mimeType要改為: image/jpeg

    當(dāng)在文件管理器里點擊任何文件, 系統(tǒng)都會試圖去執(zhí)行你的程序.

    posted @ 2011-02-11 14:49 九寶 閱讀(632) | 評論 (0)編輯 收藏

    Android Log Analysis

    轉(zhuǎn)自 http://chaozhong84.spaces.live.com/blog/cns!FC149E9A3FC0182B!297.trak

    【Android】【轉(zhuǎn)】Android Log Analysis

    ---------------------------------------------------

    本文原創(chuàng),轉(zhuǎn)載請注明出處,如有錯誤之處歡迎指出

    ---------------------------------------------------

    Get Log from Android System

    adb bugreport > bugreport.txt

    copy bugreport to the current directory.

    bugreport里面包含了各種log信息,大部分log也可以通過直接運行相關(guān)的程序來直接獲得.

    步驟如下:

    1.adb shell 2.進入相關(guān)工具程式的目錄 3.執(zhí)行相關(guān)程式 4.得到相關(guān)信息

    下面以輸出進程信息為例 1.adb shell 2.輸入ps -P 3.可以看到相關(guān)進程信息

    Log Archive Analysis

    1.bugreport

    bugreport記錄android啟動過程的log,以及啟動后的系統(tǒng)狀態(tài),包括進程列表,內(nèi)存信息,VM信息等等到.

    2.bugreport結(jié)構(gòu)分析

    (1)dumpstate

    MEMORY INFO

    獲取該log:讀取文件/proc/meminfo

    系統(tǒng)內(nèi)存使用狀態(tài)

    CPU INFO

    獲取該log:執(zhí)行/system/bin/top -n 1 -d 1 -m 30 -t

    系統(tǒng)CPU使用狀態(tài)

    PROCRANK

    獲取該log:執(zhí)行/system/bin/procrank

    執(zhí)行/system/xbin/procrank后輸出的結(jié)果,查看一些內(nèi)存使用狀態(tài)

    VIRTUAL MEMORY STATS

    獲取該log:讀取文件/proc/vmstat

    虛擬內(nèi)存分配情況

    vmalloc申請的內(nèi)存則位于vmalloc_start~vmalloc_end之間,與物理地址沒有簡單的轉(zhuǎn)換關(guān)系,雖然在邏輯上它們也是連續(xù)的,但是在物理上它們不要求連續(xù)。

    VMALLOC INFO

    獲取該log:讀取文件/proc/vmallocinfo

    虛擬內(nèi)存分配情況

    SLAB INFO

    獲取該log:讀取文件/proc/slabinfo

    SLAB是一種內(nèi)存分配器.這里輸出該分配器的一些信息

    ZONEINFO

    獲取該log:讀取文件/proc/zoneinfo

    zone info

    SYSTEM LOG(需要著重分析)

    獲取該log:執(zhí)行/system/bin/logcat -v time -d *:v

    會輸出在程序中輸出的Log,用于分析系統(tǒng)的當(dāng)前狀態(tài)

    VM TRACES

    獲取該log:讀取文件/data/anr/traces.txt

    因為每個程序都是在各自的VM中運行的,這個Log是現(xiàn)實各自VM的一些traces

    EVENT LOG TAGS

    獲取該log:讀取文件/etc/event-log-tags

    EVENT LOG

    獲取該log:執(zhí)行/system/bin/logcat -b events -v time -d *:v

    輸出一些Event的log

    RADIO LOG

    獲取該log:執(zhí)行/system/bin/logcat -b radio -v time -d *:v

    顯示一些無線設(shè)備的鏈接狀態(tài),如GSM,PHONE,STK(Satellite Tool Kit)...

    NETWORK STATE

    獲取該log:執(zhí)行/system/bin/netcfg (得到網(wǎng)絡(luò)鏈接狀態(tài))

    獲取該log:讀取文件/proc/net/route (得到路由狀態(tài))

    顯示網(wǎng)絡(luò)鏈接和路由

    SYSTEM PROPERTIES

    獲取該log:參考代碼實現(xiàn)

    顯示一些系統(tǒng)屬性,如Version,Services,network...

    KERNEL LOG

    獲取該log:執(zhí)行/system/bin/dmesg

    顯示Android內(nèi)核輸出的Log

    KERNEL WAKELOCKS

    獲取該log:讀取文件/proc/wakelocks

    內(nèi)核對一些程式和服務(wù)喚醒和休眠的一些記錄

    KERNEL CPUFREQ

    (Linux kernel CPUfreq subsystem) Clock scaling allows you to change the clock speed of the CPUs on the fly.

    This is a nice method to save battery power, because the lower the clock speed is, the less power the CPU consumes.

    PROCESSES

    獲取該log:執(zhí)行ps -P

    顯示當(dāng)前進程

    PROCESSES AND THREADS

    獲取該log:執(zhí)行ps -t -p -P

    顯示當(dāng)前進程和線程

    LIBRANK

    獲取該log:執(zhí)行/system/xbin/librank

    剔除不必要的library

    BINDER FAILED TRANSACTION LOG

    獲取該log:讀取文件/proc/binder/failed_transaction_log

    BINDER TRANSACTION LOG

    獲取該log:讀取文件/proc/binder/transaction_log

    BINDER TRANSACTIONS

    獲取該log:讀取文件/proc/binder/transactions

    BINDER STATS

    獲取該log:讀取文件/proc/binder/stats

    BINDER PROCESS STATE

    獲取該log:讀取文件/proc/binder/proc/*

    bind相關(guān)的一些狀態(tài)

    FILESYSTEMS

    獲取該log:執(zhí)行/system/bin/df

    主要文件的一些容量使用狀態(tài)(cache,sqlite,dev...)

    PACKAGE SETTINGS

    獲取該log:讀取文件/data/system/packages.xml

    系統(tǒng)中package的一些狀態(tài)(訪問權(quán)限,路徑...),類似Windows里面的一些lnk文件吧.

    PACKAGE UID ERRORS

    獲取該log:讀取文件/data/system/uiderrors.txt

    錯誤信息

    KERNEL LAST KMSG LOG

    最新kernel message log

    LAST RADIO LOG

    最新radio log

    KERNEL PANIC CONSOLE LOG

    KERNEL PANIC THREADS LOG

    控制臺/線程的一些錯誤信息log

    BACKLIGHTS

    獲取該log:獲取LCD brightness讀/sys/class/leds/lcd-backlight/brightness

    獲取該log:獲取Button brightness讀/sys/class/leds/button-backlight/brightness

    獲取該log:獲取Keyboard brightness讀/sys/class/leds/keyboard-backlight/brightness

    獲取該log:獲取ALS mode讀/sys/class/leds/lcd-backlight/als

    獲取該log:獲取LCD driver registers讀/sys/class/leds/lcd-backlight/registers

    獲取相關(guān)亮度的一些信息

    (2)build.prop

    VERSION INFO輸出下列信息
    當(dāng)前時間
    當(dāng)前內(nèi)核版本:可以讀取文件(/proc/version)獲得
    顯示當(dāng)前命令:可以讀取文件夾(/proc/cmdline)獲得
    顯示系統(tǒng)build的一些屬性:可以讀取文件(/system/build.prop)獲得
    輸出系統(tǒng)一些屬性
    gsm.version.ril-impl
    gsm.version.baseband
    gsm.imei
    gsm.sim.operator.numeric
    gsm.operator.alpha

    (3)dumpsys

    執(zhí)行/system/bin/dumpsys后可以獲得這個log.
    經(jīng)常會發(fā)現(xiàn)該log輸出不完整,因為代碼里面要求該工具最多只執(zhí)行60ms,可能會導(dǎo)致log無法完全輸出來.
    可以通過修改時間參數(shù)來保證log完全輸出.
    信息:
    Currently running services
    DUMP OF SERVICE services-name(running)

    Log Code Analysis

    Site: ."frameworks"base"cmds"dumpstate"

    相關(guān)Log程序的代碼可以從上面目錄獲取

    Log Analysis Experience

    分析步驟

    1.查看一些版本信息
    確認(rèn)問題的系統(tǒng)環(huán)境
    2.查看CPU/MEMORY的使用狀況
    看是否有內(nèi)存耗盡,CPU繁忙這樣的背景情況出現(xiàn).
    3.分析traces
    因為traces是系統(tǒng)出錯以后輸出的一些線程堆棧信息,可以很快定位到問題出在哪里. 
    4.分析SYSTEM LOG
    系統(tǒng)Log詳細(xì)輸出各種log,可以找出相關(guān)log進行逐一分析

    實例分析

    下面分析我寫的一個測試?yán)?在OnCreate做一個死循環(huán),這樣主線程會被鎖住,在按下硬件的Back之后會出現(xiàn)ANR的錯誤.
    在traces中發(fā)現(xiàn)該程序的堆棧信息如下:

    ----- pid 20597 at 2010-03-15 01:29:53 -----
    Cmd line: com.android.test
    DALVIK THREADS:
    "main" prio=5 tid=3 TIMED_WAIT
    | group="main" sCount=1 dsCount=0 s=N obj=0x2aac6240 self=0xbda8
    | sysTid=20597 nice=0 sched=0/0 cgrp=default handle=1877232296
    at java.lang.VMThread.sleep(Native Method)
    at java.lang.Thread.sleep(Thread.java:1306)
    at java.lang.Thread.sleep(Thread.java:1286)
    at android.os.SystemClock.sleep(SystemClock.java:114)
    at com.android.test.main.onCreate(main.java:20)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
    "Binder Thread #2" prio=5 tid=11 NATIVE
    | group="main" sCount=1 dsCount=0 s=N obj=0x2fb7c260 self=0x143860
    | sysTid=20601 nice=0 sched=0/0 cgrp=default handle=1211376
    at dalvik.system.NativeStart.run(Native Method)
    "Binder Thread #1" prio=5 tid=9 NATIVE
    | group="main" sCount=1 dsCount=0 s=N obj=0x2fb7c1a0 self=0x14c980
    | sysTid=20600 nice=0 sched=0/0 cgrp=default handle=1207920
    at dalvik.system.NativeStart.run(Native Method)
    "Signal Catcher" daemon prio=5 tid=7 RUNNABLE
    | group="system" sCount=0 dsCount=0 s=N obj=0x2fb7a1e8 self=0x126cc0
    | sysTid=20599 nice=0 sched=0/0 cgrp=default handle=1269048
    at dalvik.system.NativeStart.run(Native Method)
    "HeapWorker" daemon prio=5 tid=5 VMWAIT
    | group="system" sCount=1 dsCount=0 s=N obj=0x2e31daf0 self=0x135c08
    | sysTid=20598 nice=0 sched=0/0 cgrp=default handle=1268528
    at dalvik.system.NativeStart.run(Native Method)
    ----- end 20597 -----

    該文件的堆棧結(jié)構(gòu)從下往上進行分析
    (1)棧底at dalvik.system.NativeStart.run(Native Method)
    系統(tǒng)為當(dāng)前的task(應(yīng)用程式)啟動一個專用的虛擬機 
    (2) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
    Activity Services是在后臺負(fù)責(zé)管理Activity,它此時將測試?yán)拥腁ctivity啟動起來了
    (3)at com.android.test.main.onCreate(main.java:20)
    啟動測試程序
    (4)棧頂at java.lang.VMThread.sleep(Native Method)
    線程被sleep掉了,所以無法響應(yīng)用戶,出現(xiàn)ANR錯誤.

    上面是對一個非常簡單的問題的分析.

    如果遇到比較復(fù)雜的問題還需要詳細(xì)分析SYSTEM LOG.
    1.比如網(wǎng)絡(luò)異常,要通過SYSTEM LOG里面輸出的網(wǎng)絡(luò)鏈接信息來判斷網(wǎng)絡(luò)狀態(tài)
    2.數(shù)據(jù)傳輸,網(wǎng)絡(luò)鏈接等耗時的操作需要分析SYSTEM LOG里面ActivityManager的響應(yīng)時間

    posted @ 2011-01-17 11:41 九寶 閱讀(804) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 亚洲AV成人影视在线观看| 亚洲成在人天堂一区二区| 亚洲精品国产高清在线观看| 亚洲精品成人网久久久久久| 精品一区二区三区免费毛片爱| 亚洲中文久久精品无码1| 高清国语自产拍免费视频国产 | 老司机精品免费视频| 亚洲乱码一区二区三区国产精品| 亚洲成a人片在线播放| 手机在线免费视频| 久久久www成人免费毛片 | 亚洲va久久久噜噜噜久久狠狠 | 亚洲色欲久久久综合网东京热| 亚洲精品V天堂中文字幕| 全免费毛片在线播放| 亚洲国产日韩视频观看| 曰皮全部过程视频免费国产30分钟| 亚洲av乱码中文一区二区三区| 国产国产人免费视频成69大陆| 黄色网址大全免费| 国产亚洲精品不卡在线| 午夜视频在线免费观看| 亚洲va乱码一区二区三区| 免费无码又爽又刺激毛片| www.xxxx.com日本免费| 亚洲AV无码久久精品成人| 免费福利在线播放| 男男gay做爽爽免费视频| 亚洲成色www久久网站夜月| 亚洲视频免费在线播放| 亚洲成a∨人片在无码2023 | 亚洲国产精品综合久久久| 成人毛片18女人毛片免费视频未 | 美女被吸屁股免费网站| 亚洲成亚洲乱码一二三四区软件| 99久久久精品免费观看国产 | 久久国产精品国产自线拍免费| 亚洲一区免费在线观看| 免费人妻av无码专区| 一级毛片aaaaaa免费看|