Search in sources :

Example 26 with Collection

use of com.tvd12.dahlia.core.entity.Collection in project dahlia by youngmonkeys.

the class DahliaCoreLoader method loadCollection.

protected void loadCollection(Collection collection, CollectionStorage storage) {
    CollectionSetting setting = collection.getSetting();
    FieldSetting idSetting = setting.getId();
    long recordPosition = collection.getDataSize();
    while (storage.hasMoreRecords(recordPosition)) {
        Record record = storage.readRecord(recordPosition, idSetting);
        if (record != null)
            collection.insert(record);
        recordPosition = collection.increaseDataSize();
    }
}
Also used : FieldSetting(com.tvd12.dahlia.core.setting.FieldSetting) CollectionSetting(com.tvd12.dahlia.core.setting.CollectionSetting) Record(com.tvd12.dahlia.core.entity.Record)

Example 27 with Collection

use of com.tvd12.dahlia.core.entity.Collection in project ezyfox-server by youngmonkeys.

the class EzySimpleServerContextBuilder method newZoneContexts.

protected Collection<EzyZoneContext> newZoneContexts(EzyServerContext parent) {
    Collection<EzyZoneContext> contexts = new ArrayList<>();
    EzySettings settings = EzyServerContexts.getSettings(parent);
    for (Integer zoneId : settings.getZoneIds()) {
        EzyZoneSetting zoneSetting = settings.getZoneById(zoneId);
        EzySimpleZone zone = new EzySimpleZone();
        zone.setSetting(zoneSetting);
        EzyUserDelegate userDelegate = newUserDelegate(parent);
        EzyZoneUserManager userManager = newZoneUserManager(zoneSetting, userDelegate);
        EzyEventControllers eventControllers = newEventControllers(zoneSetting.getEventControllers());
        zone.setUserManager(userManager);
        zone.setEventControllers(eventControllers);
        EzySimpleZoneContext zoneContext = new EzySimpleZoneContext();
        zoneContext.setParent(parent);
        zoneContext.setZone(zone);
        zoneContext.addAppContexts(newAppContexts(zoneContext));
        zoneContext.addPluginContexts(newPluginContexts(zoneContext));
        zoneContext.init();
        contexts.add(zoneContext);
        processWithException(((EzyStartable) userManager)::start);
    }
    return contexts;
}
Also used : EzyEventControllers(com.tvd12.ezyfoxserver.wrapper.EzyEventControllers) ArrayList(java.util.ArrayList) EzyUserDelegate(com.tvd12.ezyfoxserver.delegate.EzyUserDelegate) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)

Example 28 with Collection

use of com.tvd12.dahlia.core.entity.Collection in project ezyfox-server by youngmonkeys.

the class EzyPluginSendResponseImpl method execute.

@Override
public void execute(EzyData data, Collection<EzySession> recipients, boolean encrypted, EzyTransportType transportType) {
    EzyResponse response = newResponse(data);
    serverContext.send(response, recipients, encrypted, transportType);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 29 with Collection

use of com.tvd12.dahlia.core.entity.Collection in project ezyfox-server by youngmonkeys.

the class EzyStreamBytesImpl method execute.

@Override
public void execute(byte[] bytes, Collection<EzySession> recipients, EzyTransportType transportType) {
    EzyStreamingApi streamingApi = server.getStreamingApi();
    EzySimpleBytesPackage pack = newPackage(bytes, transportType);
    pack.addRecipients(recipients);
    try {
        streamingApi.response(pack);
    } catch (Exception e) {
        logger.warn("send: {} bytes, to client: {} error", bytes.length, getRecipientsNames(recipients), e);
    } finally {
        pack.release();
    }
}
Also used : EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleBytesPackage(com.tvd12.ezyfoxserver.socket.EzySimpleBytesPackage)

Example 30 with Collection

use of com.tvd12.dahlia.core.entity.Collection in project ezyfox-server by youngmonkeys.

the class EzyAbstractResponseApi method secureResponse.

protected final void secureResponse(EzyPackage pack, boolean immediate) throws Exception {
    EzyConstant connectionType = getConnectionType();
    Collection<EzySession> recipients = pack.getRecipients(connectionType);
    if (recipients.isEmpty()) {
        return;
    }
    byte[] messageContent = dataToMessageContent(pack.getData());
    if (immediate) {
        for (EzySession session : recipients) {
            byte[] bytes = encryptMessageContent(messageContent, session.getSessionKey());
            session.sendNow(createPacket(bytes, pack));
        }
    } else {
        for (EzySession session : recipients) {
            byte[] bytes = encryptMessageContent(messageContent, session.getSessionKey());
            session.send(createPacket(bytes, pack));
        }
    }
}
Also used : EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Aggregations

Collection (com.tvd12.dahlia.core.entity.Collection)17 CollectionSetting (com.tvd12.dahlia.core.setting.CollectionSetting)16 EzyObject (com.tvd12.ezyfox.entity.EzyObject)13 CollectionStorage (com.tvd12.dahlia.core.storage.CollectionStorage)11 Record (com.tvd12.dahlia.core.entity.Record)10 FieldSetting (com.tvd12.dahlia.core.setting.FieldSetting)10 EzyArray (com.tvd12.ezyfox.entity.EzyArray)10 RecordConsumer (com.tvd12.dahlia.core.function.RecordConsumer)5 DatabaseSetting (com.tvd12.dahlia.core.setting.DatabaseSetting)5 CollectionExistedException (com.tvd12.dahlia.exception.CollectionExistedException)5 CollectionNotFoundException (com.tvd12.dahlia.exception.CollectionNotFoundException)5 DuplicatedIdException (com.tvd12.dahlia.exception.DuplicatedIdException)5 CommandCreateCollection (com.tvd12.dahlia.core.command.CommandCreateCollection)4 Database (com.tvd12.dahlia.core.entity.Database)4 DatabaseExistedException (com.tvd12.dahlia.exception.DatabaseExistedException)4 FindOptions (com.tvd12.dahlia.query.FindOptions)4 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)4 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)4 ArrayList (java.util.ArrayList)4 ICollection (com.tvd12.dahlia.ICollection)3