Skip to content

Commit

Permalink
Now uses Unloader to unload objects/members in the background. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 7, 2024
1 parent 15f6f8d commit f080e27
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Source/BoldSystemCopy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface
BoldDomainElement,
BoldDefs,
BoldUMLTypes,
BoldUnloader,
System.SysUtils,
Winapi.Windows;

Expand Down Expand Up @@ -53,6 +54,8 @@ TBoldSystemCopy = class(TComponent)
fStopped: Integer;
fStartTime: TDateTime;
FMaxObjectsInMemory: integer;
fSourceUnloader, fDestinationUnloader: TBoldUnloader;
fLastCheckStop: TDateTime;
function GetDestinationSystem: TBoldSystem;
function GetSourceSystem: TBoldSystem;
procedure CollectMembers(AClassTypeInfo: TBoldClassTypeInfo; AMemberIdList: TBoldMemberIdList; ARoleTypes: TBoldRoleSet; AAttributes: boolean; ADerived: boolean = false; ADelayedFetched: boolean = false);
Expand Down Expand Up @@ -195,6 +198,12 @@ procedure TBoldSystemCopy.CheckStop;
DoLogEvent('Use requested abort');
raise EBoldSystemCopyInterrupt.Create('Use requested abort.');
end;
if SecondsBetween(now, fLastCheckStop) > 30 then
begin
fSourceUnloader.Tick;
fDestinationUnloader.Tick;
fLastCheckStop := now;
end;
end;

procedure TBoldSystemCopy.CloneObject(const ASourceObject: TBoldObject;
Expand Down Expand Up @@ -738,7 +747,17 @@ procedure TBoldSystemCopy.Report(const Msg: string; const Args: array of const);
end;

procedure TBoldSystemCopy.Run;
var
g: IBoldGuard;
begin
g := TBoldGuard.Create(fSourceUnloader, fDestinationUnloader);
fSourceUnloader := TBoldUnloader.Create;
fDestinationUnloader := TBoldUnloader.Create;
fSourceUnloader.ScanPerTick := 500;
fDestinationUnloader.ScanPerTick := 500;
fSourceUnloader.MinAgeForUnload := 20; // 20 * 30 sec
fDestinationUnloader.MinAgeForUnload := 20;

fStopped := 0;
fNewObjectsWritten := 0;
if not Assigned(SourceSystemHandle) then
Expand All @@ -763,20 +782,27 @@ procedure TBoldSystemCopy.Run;
DestinationSystem.OnPreUpdate := PreUpdateDestination;
fStartTime := now;
try
fSourceUnloader.BoldSystem := SourceSystem;;
fDestinationUnloader.BoldSystem := DestinationSystem;
fLastCheckStop := now;
fSourceUnloader.Active := true;
fDestinationUnloader.Active := true;
CheckStop;
CheckModelCompatibility;
Report('Source objects: %d Destination objects %d', [SourceAllInstanceCount, DestinationAllInstanceCount]);
CheckStop;
CopyInstances;
UpdateLastUsedID;
fSourceUnloader.Active := false;
fDestinationUnloader.Active := false;
Report('Completed succesfully, source: %d destination: %d.', [SourceAllInstanceCount, DestinationAllInstanceCount]);
SourceSystemHandle.Active := false;
// DestinationSystemHandle.Active := false;
except
on e:EBoldSystemCopyInterrupt do
begin
fStartTime := 0;
; // silent
raise;
end;
end;
end;
Expand Down

0 comments on commit f080e27

Please sign in to comment.