Package bm.core.event

Examples of bm.core.event.ProgressEvent


    {
        final Hashtable map = Store.map;
        final int count = map.size();
        if( count > 0 )
        {
            final ProgressEvent pe = new ProgressEvent();
            pe.setAnimate( false );
            pe.setMessage( "" );
            pe.setPhase( "" );
            pe.setTitle( ResourceManager.getResource( "db.shutdown.Title" ) );
            pe.setMaxValue( new Integer( count ) );
            pe.setCurrentValue( 0 );
            pe.dispatch();
            int index = 1;
            //noinspection MethodCallInLoopCondition
            for( Enumeration i = map.elements(); i.hasMoreElements(); )
            {
                pe.setMessage( index + "/" + count );
                index++;
                pe.increment();
                pe.dispatch();
                final Store store = (Store) i.nextElement();
                try
                {
                    store.shutdown();
                }
                catch( Exception e )
                {
                    log.error( e );
                }
            }
            pe.increment();
            pe.dispatch();
            map.clear();
        }
    }
View Full Code Here


    protected void showSearchingProgress( final ControllerEvent event )
    {
        final String title = ResourceManager.getResource(
                "global.Searching"
        );
        final ProgressEvent pe = new ProgressEvent(
                event.getSource(),
                new Integer( Gauge.INDEFINITE ),
                Gauge.CONTINUOUS_RUNNING
        );
        pe.setTitle( title );
        pe.setPhase( title );
        pe.dispatch();
    }
View Full Code Here

    /**
     * Ensure close all open recordstores.
     */
    public static synchronized void shutdownAll()
    {
        final ProgressEvent pe = new ProgressEvent();
        pe.setAnimate( true );
        pe.setMessage( "" );
        pe.setPhase( "" );
        pe.setTitle( ResourceManager.getResource( "db.shutdown.Title" ) );
        pe.dispatch();

        final String[] names = RecordStore.listRecordStores();
        if( names != null )
        {
            final int count = names.length;
            pe.setMaxValue( new Integer( count ) );
            pe.setCurrentValue( 0 );
            pe.setAnimate( false );
            pe.dispatch();
            for( int i = 0; i < count; i++ )
            {
                pe.setMessage( (i+1) + "/" + count );
                pe.increment();
                pe.dispatch();
                try
                {
                    safeCloseRecordStore( names[i] );
                }
                catch( RSException e )
                {
                    log.error( e );
                }
                catch( RecordStoreFullException e )
                {
                    log.error( e );
                }
            }
            pe.increment();
            pe.dispatch();
        }
    }
View Full Code Here

     */
    public synchronized void packCopy()
            throws RSException,
                   RecordStoreFullException
    {
        ProgressEvent pe = new ProgressEvent();
        pe.setAnimate( true );
        pe.setTitle( ResourceManager.getResource( "rs.packing" ) );
        pe.setPhase( ResourceManager.getResource( "rs.packing" ) );
        pe.setSource( this );
        pe.dispatch();

        shutdown();
        open();
        RecordStore pack = null;
        try
        {
            final byte[] empty = new byte[1];
            pack = RecordStore.openRecordStore( info.name + "_bak", true );
            final int count = rs.getNextRecordID();
            pe.setAnimate( false );
            pe.setMaxValue( new Integer( (count - 1) * 2 ) );
            pe.setCurrentValue( 0 );
            pe.dispatch();
            for( int i = 1; i < count; i++ )
            {
                try
                {
                    final byte[] data = rs.getRecord( i );
                    pack.addRecord( data, 0, data.length );
                }
                catch( javax.microedition.rms.InvalidRecordIDException e )
                {
                    pack.addRecord( empty, 0, 1 );
                    pack.deleteRecord( i );
                }
                pe.increment();
                pe.dispatch();
            }
            drop();
            open();
            for( int i = 1; i < count; i++ )
            {
                try
                {
                    final byte[] data = pack.getRecord( i );
                    rs.addRecord( data, 0, data.length );
                }
                catch( javax.microedition.rms.InvalidRecordIDException e )
                {
                    rs.addRecord( empty, 0, 1 );
                    rs.deleteRecord( i );
                }
                pe.increment();
                pe.dispatch();
            }
        }
        catch( RecordStoreException e )
        {
            log.error( e );
View Full Code Here

                   SerializationException,
                   IOException,
                   RemoteCallException
    {
        final Binding binding = Binding.create();
        final ProgressEvent pe = new ProgressEvent();
        pe.setAnimate( true );
        pe.setSource( this );
        try
        {
            pe.setMessage( ResourceManager.getResource( "bm.net.rpc.SendingCall" ) );
            pe.dispatch();
            binding.open( url );
            final DataOutputStream dos = binding.beginPost();
            final ChecksumedOutputStream cos = new ChecksumedOutputStream( dos );
            final DataOutputStream dos2 = new DataOutputStream( cos );
            final SerializerOutputStream out = new SerializerOutputStream( dos2 );
            out.writeByte( VERSION );
            out.writeByte( (byte) (encrypted ? 1 : 0) );
            out.writeString( Net.getDeviceGuid() != null ? Net.getDeviceGuid() : "" );
            out.writeLong( Net.getDeviceId() != null ? Net.getDeviceId().longValue() : 0 );
            serialize( out );
            final long crc  = cos.getCRC();
            out.writeString( "END_OF_DATA" );
            out.writeLong( crc );
            pe.setMessage( ResourceManager.getResource( "bm.net.rpc.WaitingResponse" ) );
            pe.dispatch();
            log.debug( "Call serialized" );
            final DataInputStream is = binding.endPost();
            final SerializerInputStream in = new SerializerInputStream( is );
            pe.setMessage( ResourceManager.getResource( "bm.net.rpc.ReadingResponse" ) );
            pe.dispatch();
            final int responseCode = in.readInt();
            final String responseMessage = in.readString();
            if( responseCode == Net.RC_SUCCESS )
            {
                return in.readNullableObject();
View Full Code Here

            {
                open();

                loadStructure();

                final ProgressEvent event = new ProgressEvent();
                event.setSource( this );

                event.setCurrentValue( 1 );
                event.setMaxValue( new Integer( 2 ) );
                event.setPhase( ResourceManager.getResource(
                        "db.start.startSystem"
                ) );
                ProgressEvent.dispatch( event );

                event.setPhase( ResourceManager.getResource(
                        "db.start.Starting"
                ) );
                event.setMessage( event.getPhase() );
                ProgressEvent.dispatch( event );
                // Now build objects
                softStart( event );
                event.increment();
                ProgressEvent.dispatch( event );

                started = true;

                event.setCurrentValue( 2 );
                event.setMaxValue( new Integer( 2 ) );
                event.setPhase( ResourceManager.getResource(
                        "db.start.startSystem"
                ));
                event.setMessage( ResourceManager.getResource(
                        "global.Done"
                ) );
                ProgressEvent.dispatch( event );
                log.info( "Started" );
            }
View Full Code Here

            }
            int recordId;
            int recordSize;
            byte rowType;
            //noinspection MethodCallInLoopCondition
            final ProgressEvent event = new ProgressEvent();
            event.setSource( this );
            event.setCurrentValue( 0 );
            event.setPhase( ResourceManager.getResource(
                    "db.start.startSystem"
            ) );
            event.setMaxValue( new Integer( 2 ) );
            ProgressEvent.dispatch( event );

            final int length = rids.length;

            event.setCurrentValue( 0 );
            event.setPhase( ResourceManager.getResource(
                    "db.start.loadData"
            ) );
            event.setMaxValue( new Integer( length ) );
            ProgressEvent.dispatch( event );
            //noinspection MethodCallInLoopCondition
            for( int i = 0; i < length; i++ )
            {
                recordId = rids[i];
                // Skip header record
                if( recordId > 1 )
                {
                    recordSize = rs.getRecordSize( recordId );
                    if( recordSize > data.length )
                    {
                        try
                        {
                            data = Tools.secureAlloc(
                                    recordSize + Constants.GROWTH_FACTOR
                            );
                        }
                        catch( J2MEException e )
                        {
                            log.error( e );
                            ErrorLog.addError(
                                    "Database",
                                    "loadStructure",
                                    null,
                                    null,
                                    e
                            );
                            throw new DBException(
                                    Constants.ERR_DB_LOAD_STRUCTURE,
                                    e
                            );
                        }
                    }
                    rs.getRecord( recordId, data, 0 );
                    ByteArrayInputStream bais = new ByteArrayInputStream( data, 0, recordSize );
                    SerializerInputStream in = new SerializerInputStream( bais );
                    rowType = in.readByte();
                    switch( rowType )
                    {
                        case Constants.DBRT_TABLE_INFO:
                            final TableInfo info = new TableInfo();
                            info.deserialize( in );
                            info.setRecordId( recordId );
                            tableInfo.put( info.getName(), info );
                            tableInfoList.addElement( info );
                            break;

                        case Constants.DBRT_TABLE_STATUS:
                            final TableStatus status = new TableStatus( this );
                            status.deserialize( in );
                            status.setRecordId( recordId );
                            tableStatus.put( status.getTableName(), status );
                            break;
                    }
                    event.increment();
                    ProgressEvent.dispatch( event );
                }
            }
            event.increment();
            ProgressEvent.dispatch( event );
        }
        catch( Exception e )
        {
            log.error( e );
View Full Code Here

                   SerializationException,
                   RecordStoreFullException,
                   RSException,
                   InvalidRecordIDException
    {
        final ProgressEvent pe = new ProgressEvent( this );
        final int size = tableInfoList.size();
        pe.setAnimate( false );
        pe.setCancellable( true );
        pe.setMaxValue( new Integer( size ) );
        pe.setPhase( ResourceManager.getResource( "db.packing" ) );
        for( int i = 0; i < size && !ControlledTask.isCancelled(); i++ )
        {
            final TableInfo tableInfo =
                    (TableInfo) tableInfoList.elementAt( i );
            pe.setMessage( ResourceManager.getResource(
                    "tableNames." + tableInfo.getName()
            ) );
            pe.dispatch();
            final Table table = (Table) tables.get( tableInfo.getName() );
            table.pack();
            pe.increment();
            pe.dispatch();
        }
    }
View Full Code Here

            throws DBException,
                   SerializationException,
                   RecordStoreFullException,
                   RSException
    {
        final ProgressEvent pe = new ProgressEvent( this );
        final int size = tableInfoList.size();
        pe.setAnimate( false );
        pe.setCancellable( true );
        pe.setMaxValue( new Integer( size ) );
        pe.setPhase( ResourceManager.getResource( "db.repairing" ) );
        final Hashtable damaged = new Hashtable( 10 );
        for( int i = 0; i < size && !ControlledTask.isCancelled(); i++ )
        {
            final TableInfo tableInfo =
                    (TableInfo) tableInfoList.elementAt( i );
            pe.setMessage( ResourceManager.getResource(
                    "tableNames." + tableInfo.getName()
            ) );
            pe.dispatch();
            final IndexInfo[] indexInfo = tableInfo.getIndexInfo();
            if( indexInfo != null && indexInfo.length > 0 )
            {
                damaged.clear();
                final Table table = (Table) tables.get( tableInfo.getName() );
                final int indexCount = indexInfo.length;
                for( int j = 0; j < indexCount; j++ )
                {
                    final Index index = table.getIndex( j );
                    if( index.isDamaged() )
                    {
                        damaged.put( indexInfo[j].getFieldNames(), index );
                    }
                }
                if( damaged.size() > 0 )
                {
                    table.rebuildIndexes( damaged );
                }
            }
            pe.increment();
            pe.dispatch();
        }
    }
View Full Code Here

    private static ProgressEvent pe = new ProgressEvent();

    public static String getErrors()
            throws J2MEException
    {
        final ProgressEvent pe = ErrorLog.pe;
        final StringBuffer buffer = new StringBuffer();
        RecordStore rs = null;
        try
        {
            pe.setAnimate( true );
            pe.setPhase( ResourceManager.getResource( "errorlog.building" ) );
            pe.setMessage( "" );
            pe.dispatch();
            rs = RecordStore.openRecordStore( RS_NAME, true );
            int first = 1;
            int count = rs.getNumRecords();
            if( count > MAX_RECORDS )
            {
                first = count - MAX_RECORDS;
                count = MAX_RECORDS;
            }
            pe.setAnimate( false );
            pe.setMaxValue( new Integer( count ) );
            pe.setCurrentValue( 0 );
            pe.dispatch();
            int index = first;
            for( int i = 0; i < count; i++, index++ )
            {
                final ByteArrayInputStream bais = new ByteArrayInputStream(
                        rs.getRecord( index )
                );
                final DataInputStream dis = new DataInputStream( bais );
                final SerializerInputStream in =
                        new SerializerInputStream( dis );
                buffer.append( in.readString() ).append( '\n' );
                pe.increment();
                pe.dispatch();
            }
            return buffer.toString();
        }
        catch( Exception e )
        {
View Full Code Here

TOP

Related Classes of bm.core.event.ProgressEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.